API - Angular Runtime Dimension - Error 424

Hi all

I am trying to create an angular execution dimension on an MEP via the APIs. I select my entities but when I get to the AddAngularRunningDim line, I get a 424 error. The most worrying thing is that the example given by Dassault also contains this error. I did add the references in Visual Basic.

Where can this error come from?

 

Thank you for your help.

Mickael

You probably forgot to assign an object, can we see your code?

1 Like

It's a code under construction, thanks for your indulgence. ^^

I only took the example by adapting it to my model,

The example is available here:

http://help.solidworks.com/2016/English/api/sldworksapi/Set_Properties_of_Angular_Running_Dimension_Example_VB.htm

 

 

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swmodel As SldWorks.ModelDocExtension
Sun selmgr As SldWorks.SelectionMgr
Dim dispdim As SldWorks.DisplayDimension
Dim boolstatus As Boolean
Dim errstatus As Long

Option Explicit

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set swmodel = Part.Extension
    
    boolstatus = Part.ActivateView("Layout View1")
    boolstatus = swmodel. SelectByID2("Line5@Esquisse3D4@Fonds-GRC-Drawing 3@Vue 1", "EXTSKETCHSEGMENT", 0.567145629669376, 0.556256162693586, 0, True, 0, Nothing, 0)
    boolstatus = swmodel. SelectByID2("Line5@Esquisse3D5@Fonds-GRC-Drawing 3@Vue", "EXTSKETCHSEGMENT", 0.159796832575413, 0.661760850386628, 0, True, 0, Nothing, 0)
   
    

    Set dispdim = swmodel. AddAngularRunningDim(True, False, True, 0.56, 0.64, 0, errstatus)
    Part.Extension.ReJogRunningDimension
    Part.Extension.AlignRunningDimension
    

    Part.SetPickMode

End Sub

 

In your case here, SolidWorks will look for the sketch piece Line5@Esquisse3D4@Fonds-GRC-3@Vue of drawing1 Now, from one drawing, or even from one view to another, it won't be fair.

If you're sure it's the right thing, tell me again.

 

Ps: Which line do you have the error on?

1 Like

I have the error on the line: Set dispdim = swmodel. AddAngularRunningDim(True, False, True, 0.56, 0.64, 0, errstatus)

I'm not sure if I've taken the right element, but my goal is to get the end of this line to make it the center of my angular dimension, then I select the next line and I launch the dimension with these selections. 

It's at the listing that it screws up, so I tell myself that the recovered elements don't fulfill their role well.

What I'm actually wondering is if the position of the selections (in X, Y and Z) and the rating (LocX, LocY and LocZ) are correct, but a priori the retval of the AddAngularRunningDim returns a value of 0, it's that it can't create the odds. 

In this case, do I have to retrieve the coordinates of each row I want to select them again in the SelectByID2?

As far as the LocX, Y and Z are concerned, I don't really see what they correspond to, is it the position of the "click" or the position of the value 0°?

I'll bring the subject up, does anyone have a solution?

Hello

Try changing the function's settings (True and False) to see what happens.

Kind regards.

Hello

Here is the code of the example modified and functional (but in C#, to be translated):

ModelDoc2 Part = default(ModelDoc2);
bool boolstatus = false;
int intstatus;
object obj;

Part = ((ModelDoc2)(Program.swapp. ActiveDoc));

boolstatus = Part.Extension. SelectByID2("", "EDGE", 0.163726736787323, 0.199115091463415, 0.0047999999999993197, true, 0, null, 0);
boolstatus = Part.Extension. SelectByID2("", "EDGE", 0.220795425811714, 0.179644597560976, 0.00479999999998881, true, 0, null, 0);

obj = Part.Extension. AddAngularRunningDim(false, true, true, 0.154288188900673, 0.0794194886913027, 0, out intstatus);

Part.Extension. ReJogRunningDimension();
Part.Extension. AlignRunningDimension();

Part.SetPickMode();

 

In your case, try to put the variable "dispdim" as an "object" and not as a "DisplayDimension".

Kind regards

I tried to change the true and false (all possible combinations) of the AddAngularRunningDim function, it works in the template but the error 424 still appears on this line. These properties only manage the type of dimension (line to center, arc plot of the angle, etc.)

 

I also tried to replace the dispdim declaration in Object. It doesn't work either.

 

Any other ideas? 

Hello

I tried your code last night and I also have the same error.

I also tried to record a macro of adding this type of coast and here, sw does not use this function but AddDimension2().

Try it out on a prototype model and you should have your code.

In the SelectByID2() function, if you fill in the name of the first variable, you don't need to fill in X,Y, and Z. He finds the entity without its position.

Kind regards.

Thanks for the SelectbyID2 thing, you have to put 0 everywhere to cut the desired entity. It works perfectly.

On the other hand, I had also tested the recorder and ended up with the same code with the AddDimension2 unfortunately by selecting 2 lines it does give me a dimension but it remains a simple angle dimension without the 0° which is essential to me in our job as a boilermaker, hence the interest (since the 2014 version) of the angular execution dimensions. 

I can understand how this code works (declaration of the base entity then the secondary entities then display of the 0° dimension at the LocX, LocY and LocZ  position and finally the following ones) but this error 424 is a real mystery.

Isn't there an error in the API references? (You never know and as their example also contains this error...)

Hello

Using a C# program, it is perfectly clear that there is a casting problem between the object of type 'System.Object[]' and the object of type 'SolidWorks.Interop.sldworks.DisplayDimension'. As soon as the modification made to this problem everything works normally.

I don't know enough about VBA to tell you that the problem is the same but I can assume that yes, I'll let VBA specialists answer you on this point.

Kind regards


capture.png

There is indeed a problem with the API. I opened a ticket with Solidworks which detected the same problem

I will get back to you for the rest, a correction can be made on the next Service Pack.

Thank you

Here is the correction applied by Dassault. Now this example works perfectly with the model of the adv. tutorial (foodprocessor)

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open public_documents\tutorial\advdrawings\foodprocessor.slddrw.
' 2. Open an Immediate window.
'
' Postconditions:
' 1. The specified angular running dimension is inserted into the drawing.
' 2. Inspect the Immediate window.
'
' NOTE: Because the model is used elsewhere, do not save changes to it.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim PartExt As SldWorks.ModelDocExtension
Sun selmgr As SldWorks.SelectionMgr
Dim dispdim As SldWorks.DisplayDimension
Dim swDispDim As SldWorks.DisplayDimension
Dim vdim As Variant
Dim boolstatus As Boolean
Dim errstatus As Long
Sun i As Long

Option Explicit

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set PartExt = Part.Extension
    

    boolstatus = Part.ActivateView("Drawing View1")
    boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.17648799570697, 0.195948476524618, 4.79999999998881E-03, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.270641278567064, 0.202920893989561, 4.799999999993197E-03, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.238383279638647, 0.257816085148446, -3.99999999899592E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.154059738580153, 0.26234352359454, 6.00000000247292E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.104823845478885, 0.213673560299033, 6.000000000019918E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.152361949162868, 0.163871737392003, 6.000000000019918E-04, True, 0, Nothing, 0)
    
    vdim = PartExt.AddAngularRunningDim(True, True, True, 0.154288188900673, 7.94194886913027E-02, 0, errstatus)
    Part.SetPickMode
    
    For i = 0 To UBound(vdim)
        Set dispdim = vdim(i)
        Part.Extension.ReJogRunningDimension
        Part.Extension.AlignRunningDimension
        
        Debug.Print "Display chained angular dimensions? " & dispdim. DisplayAsChain
        Debug.Print "Run the angular dimensions bidirectionally? " & dispdim. RunBidirectionally
        Debug.Print "Extend extension lines from center of angular running dimension? " & dispdim. ExtensionLineExtendsFromCenterOfSet
        Debug.Print "Are extension lines jogged? " & dispdim. Jogged
        Debug.Print "Extension line style same as leader line style? " & dispdim. ExtensionLineSameAsLeaderStyle
        Debug.Print "Extension line uses document settings? " & dispdim. ExtensionLineUseDocumentDisplay
        

    Next

End Sub

 

If I understood correctly, the problem came from the fact that the function looped each time on the same element, hence the proposal to declare a variable and a loop on the elements. 

 

Am I right?

 

Hello

What has changed:

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open public_documents\tutorial\advdrawings\foodprocessor.slddrw.
' 2. Open an Immediate window.
'
' Postconditions:
' 1. The specified angular running dimension is inserted into the drawing.
' 2. Inspect the Immediate window.
'
' NOTE: Because the model is used elsewhere, do not save changes to it.
' ---------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim PartExt As SldWorks.ModelDocExtension
Sun selmgr As SldWorks.SelectionMgr
Dim dispdim As SldWorks.DisplayDimension
Dim swDispDim As SldWorks.DisplayDimension
Dim vdim As Variant
Dim boolstatus As Boolean
Dim errstatus As Long
Sun i As Long

Option Explicit

Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set PartExt = Part.Extension
    

    boolstatus = Part.ActivateView("Drawing View1")
    boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.17648799570697, 0.195948476524618, 4.79999999998881E-03, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.270641278567064, 0.202920893989561, 4.799999999993197E-03, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.238383279638647, 0.257816085148446, -3.99999999899592E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.154059738580153, 0.26234352359454, 6.00000000247292E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.104823845478885, 0.213673560299033, 6.000000000019918E-04, True, 0, Nothing, 0)
    boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.152361949162868, 0.163871737392003, 6.000000000019918E-04, True, 0, Nothing, 0)
    
    vdim = PartExt.AddAngularRunningDim(True, True, True, 0.154288188900673, 7.94194886913027E-02, 0, errstatus)
    Part.SetPickMode
    
    For i = 0 To UBound(vdim)
        Set dispdim = vdim(i)
        Part.Extension.ReJogRunningDimension
        Part.Extension.AlignRunningDimension
        
        Debug.Print "Display chained angular dimensions? " & dispdim. DisplayAsChain
        Debug.Print "Run the angular dimensions bidirectionally? " & dispdim. RunBidirectionally
        Debug.Print "Extend extension lines from center of angular running dimension? " & dispdim. ExtensionLineExtendsFromCenterOfSet
        Debug.Print "Are extension lines jogged? " & dispdim. Jogged
        Debug.Print "Extension line style same as leader line style? " & dispdim. ExtensionLineSameAsLeaderStyle
        Debug.Print "Extension line uses document settings? " & dispdim. ExtensionLineUseDocumentDisplay

        

    Next

End Sub

In bold:

There was a casting issue in the return  value of the AddAngularRunningDim() and swDispDim function .

Incidentally, AddAngularRunningDim() returns an Array(of DisplayDimension) that vba couldn't cast to Object.

In italics, it's just a loop to display the properties of the created dimensions.

Kind regards.

1 Like

Hello

Good to know, a generic "object" in C# is therefore a "Variant" in VBA.

Kind regards

Good evening

I guess so. It's suspicious but yes ...

Kind regards