Create Complex Shape Element - argument type mismatch

Hi,

I wrote  short script for longitudinal profile… and I need draw filled half of the circle. Idea is to draw line plus  arc and then create complex shape. part of the code looks like this:

Dim carka As LineElement
Dim oblouk As ArcElement
Dim vrchol(1 To 3) As Point3d
Dim prvky(1 To 2) As ChainableElement
Dim pulkolo As ComplexShapeElement


Set carka = CreateLineElement2(Nothing, vrchol(1), vrchol(3)) 'line
Set oblouk = CreateArcElement3(Nothing, vrchol(3), vrchol(2), vrchol(1)) 'arc
Set prvky(1) = carka
Set prvky(2) = oblouk
Set pulkolo = CreateComplexShapeElement1(prvky, msdFillModeFilled)
ActiveModelReference.AddElement pulkolo
pulkolo.Redraw

When I test it, it worked; but now it doesn't. Debugging window appears with "argument type mismatch" prompt and in "Set pulkolo..." line is marked "prvky" argument. I checked help file, some examples... and I don't know, where can be the mistake.

If I comment last three lines and add these 

ActiveModelReference.AddElement carka
carka.Redraw
ActiveModelReference.AddElement oblouk
oblouk.Redraw

line and arc element appears at the right place - so they are created successfully. 

Does anybody know, what can be wrong?

Thanks,
Stepan
 

Parents
  • ChainableElement is an Interface, not a concrete class

    Dim prvky(1 To 2) As ChainableElement

    You can't create an array of ChainableElement. ChainableElement is a way of interpreting certain MicroStation element types.

    prvky(1) = oElement

    You can't assign to a ChainableElement like the above code. You can only cast an existing element using oElement.AsChainableElement.

    The way the VBA help is written makes it looks like you can have an array of ChainableElements, but that's an artefact of the formal expression of the method. But you're almost there …

    Dim oMyChainableElements(1 To 2) As Element
    Set oMyChainableElements (1) = carka
    Set oMyChainableElements (2) = oblouk
    Set pulkolo = CreateComplexShapeElement1(oMyChainableElements, msdFillModeFilled)
    

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    thank You for reply and explanation (again I am little bit smarter). I applied Your solution,

    Dim carka As LineElement
    Dim oblouk As ArcElement
    Dim vrchol(1 To 3) As Point3d
    Dim prvky(1 To 2) As Element
    Dim pulkolo As ComplexShapeElement


    Set carka = CreateLineElement2(Nothing, vrchol(1), vrchol(3)) 'line
    Set oblouk = CreateArcElement3(Nothing, vrchol(3), vrchol(2), vrchol(1)) 'arc
    Set prvky(1) = carka
    Set prvky(2) = oblouk
    Set pulkolo = CreateComplexShapeElement1(prvky, msdFillModeFilled)
    ActiveModelReference.AddElement pulkolo
    pulkolo.Redraw

    but it doesn'n work - the same error "argument type mismatch" persist.
    I added "debugging" prompts after each setting of prvky() to make sure, that these elements are ok

    Set prvky(1) = carka
    If prvky(1).IsChainableElement = True Then MsgBox ("line is chainable")
    If prvky(1).IsArcElement = True Then MsgBox ("prvky(1) is arc")
    If prvky(1).IsLineElement = True Then MsgBox ("prvky(1) is line")
    Set prvky(2) = oblouk
    If prvky(2).IsChainableElement = True Then MsgBox ("arc is chainable")
    If prvky(2).IsArcElement = True Then MsgBox ("prvky(2) is arc")
    If prvky(2).IsLineElement = True Then MsgBox ("prvky(2) is line")

    All correct messages appear (line for prvky(1), arc for prvky(2), chainable for both), so I think, that prvky() is correct.

    Do You have any idea, what can be wrong?

    Regards

    Stepan

  • Take a look at the Compound Element Example in VBA Help.

    The problem could be related to array dimensioning. By default, array indexing starts at zero, so when you do the following you create an array having two members …

    Dim array(1) As Integer  ' Contains two members!

    To take control, use explict array dimensioning …

    Dim array(0 To 1) As Integer  ' Contains two members as expected

    When you do this, you're leaving the first member of the array unassigned …

    Dim array(2)  ' Three members
    array (1) = abc
    array (2) = def
    result = ProcedureThatTakesAnArray (array)  '  array(0) was never assigned

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Take a look at the Compound Element Example in VBA Help.

    The problem could be related to array dimensioning. By default, array indexing starts at zero, so when you do the following you create an array having two members …

    Dim array(1) As Integer  ' Contains two members!

    To take control, use explict array dimensioning …

    Dim array(0 To 1) As Integer  ' Contains two members as expected

    When you do this, you're leaving the first member of the array unassigned …

    Dim array(2)  ' Three members
    array (1) = abc
    array (2) = def
    result = ProcedureThatTakesAnArray (array)  '  array(0) was never assigned

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Children
  • Hi,

    Compound Element Example was  my model, when i created my script. from there I cribbed "Dim ... AsChainableElement".

    My array prvky is dimensioned explicitly (1 To 2) with two members

    Dim prvky(1 To 2) As Array

    prvky (1) = abc
    prvky (2) = def

    prvky (0) never existed (and therefor couldn't be unassigned, I think).

     

    I return back to dimension prvky as AsChainableElement, make some tryings and now it works. Maybe there is one little dirty thing - I omit making extra objects for each element and then setting them into the array, and I create them directly.

    Dim vrchol(1 To 3) As Point3d 'three members array of points
    Dim prvky(1 To 2) As ChainableElement
    'two members array of chainable elements
    Dim pulkolo As ComplexShapeElement

    Set prvky(1) = CreateLineElement2(Nothing, vrchol(1), vrchol(3))
    'chainable line
    Set prvky(2) = CreateArcElement3(Nothing, vrchol(3), vrchol(2), vrchol(1))
    'chainable arc
    Set pulkolo = CreateComplexShapeElement1(prvky, msdFillModeFilled)
    ActiveModelReference.AddElement pulkolo
    pulkolo.Redraw

    I don't know, where the "argument type mismatch" error was. Now it works perfectly.

    Thanks for Yor interest and help.

    Regards
    Stepan