Creating a centermark from a WorkPoint of a Substitute LOD part

Creating a centermark from a WorkPoint of a Substitute LOD part

sergio_duran
Advocate Advocate
1,089 Views
6 Replies
Message 1 of 7

Creating a centermark from a WorkPoint of a Substitute LOD part

sergio_duran
Advocate
Advocate

Hi Everyone,

 

When I place dimensions and leaders in the Drawing environment with API or iLogic, I create workpoints and then I create the centermarks in order to place the dimensions with GeometryIntents. It has always worked! However, this time, I'm trying to create a centermark from a WorkPoint that comes from the part of a Substitute LevelOfDetail, but it isn't working. I'm replacing an assembly with a part and I need to get a work point from this part. Here is the code:

 

I can get the WorkPoint and WorkPoint Proxy, but when I try to create the centermark I get an error (common iLogic error, not meaningful). Any Idea? Thanks!

SyntaxEditor Code Snippet

doc = ThisDoc.Document
oAssyDoc = ThisDrawing.ModelDocument

Dim oSheet As Sheet
oSheet=doc.Sheets.Item(1)

Dim oView As DrawingView
oView=oSheet.DrawingViews.Item(1)

Dim oOccs As ComponentOccurrences
oOccs=oAssyDoc.ComponentDefinition.Occurrences

'Item #1 required Subassy 'LOD #6 - LOD Substitute
Dim oSubAssySubstituteOcc As ComponentOccurrence
oSubAssySubstituteOcc = oOccs.Item(1).Definition.RepresentationsManager.LevelOfDetailRepresentations.Item(6).SubstituteOccurrence
    
Dim oDiaPoint1 As WorkPoint
oDiaPoint1 = oSubAssySubstituteOcc.Definition.Document.ComponentDefinition.WorkPoints.Item(2)
    
Dim oDiaPoint1Proxy As WorkPointProxy
oSubAssySubstituteOcc.CreateGeometryProxy (oDiaPoint1, oDiaPoint1Proxy)

Dim oCentermarks As Centermarks
oCentermarks = oSheet.Centermarks

Dim oCMark As Centermark
oCMark = oCentermarks.AddByWorkFeature(oDiaPoint1Proxy, oView)

 

0 Likes
Accepted solutions (1)
1,090 Views
6 Replies
Replies (6)
Message 2 of 7

YuhanZhang
Autodesk
Autodesk

Can you upload a sample data to reproduce the problem? Don't upload confidential data.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 7

sergio_duran
Advocate
Advocate

Hi Rocky,

Thanks for your reply! I've uploaded a dataset named SubstituteQuestion. The Master Assembly 'MasterAssy' has two occurrences, one subassembly with Substitute Level Of Detail and the other occurrence is a regular part 'Cylinder' . The Subassembly has two parts (box 1 and box 2), but I'm using a Substitute LOD to replace it with a single part named 'SubstituteLOD part'. The Master Assembly has LOD named 'iLogic' that uses the Subassembly Substitute LOD. This is the scenario, but you actually only need to open the drawing. it has two iLogic rules. The first one creates a centermark for the regular Part Cylinder and it works very well. The second rule, tries to create the centermark for a WorkPoint in the Substitute LOD Part but it fails. As you can see both codes are very similar but the second one fails when it tries to create the centermark. I added 3 messages to show how it gets the Occurrence, the WorkPoint and the Proxy, but it fails with the centermark. Thanks!

0 Likes
Message 4 of 7

YuhanZhang
Autodesk
Autodesk
Accepted solution

I changed your code to VBA macro and update it a bit to make it work as below. The problem in your code is that you should create the WorkPoint proxy twice to get the proxy in top-assembly, but you just create the proxy once so it is still in the sub-assembly, please try below VBA code and let me if you have more questions :

 

Sub test()

Dim Doc As DrawingDocument
Set Doc = ThisApplication.ActiveDocument

Dim oAssyDoc  As AssemblyDocument
Set oAssyDoc = Doc.ReferencedDocuments(1)

Dim oSheet As Sheet
Set oSheet = Doc.Sheets.Item(1)

Dim oView As DrawingView
Set oView = oSheet.DrawingViews.Item(1)

Dim oOccs As ComponentOccurrences
Set oOccs = oAssyDoc.ComponentDefinition.Occurrences

'Item #1 required Subassy 'LOD #6 - LOD Substitute
Dim oSubAssySubstituteOcc As ComponentOccurrence
Set oSubAssySubstituteOcc = oOccs.Item(1).Definition.RepresentationsManager.LevelOfDetailRepresentations.Item(6).SubstituteOccurrence
    
Dim oDiaPoint1 As WorkPoint
Set oDiaPoint1 = oSubAssySubstituteOcc.Definition.Document.ComponentDefinition.WorkPoints.Item(2)

' get the work point proxy in the sub assembly
Dim oDiaPoint1Proxy As WorkPointProxy
Call oSubAssySubstituteOcc.CreateGeometryProxy(oDiaPoint1, oDiaPoint1Proxy)

' get the work point proxy in the top assembly
Dim oDiaPoint1Proxy2 As WorkPointProxy
Call oOccs.Item(1).CreateGeometryProxy(oDiaPoint1Proxy, oDiaPoint1Proxy2)

Dim oCentermarks As Centermarks
Set oCentermarks = oSheet.Centermarks

Dim oCMark As Centermark
Set oCMark = oCentermarks.AddByWorkFeature(oDiaPoint1Proxy2, oView)

End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 7

sergio_duran
Advocate
Advocate

Hi Rocky,

Thank you so much for your help! I actually tested in VBA editor and it worked very well. I tweaked it a little bit and tested in the iLogic editor and worked as well. I didn't know that the WorkFeature needs to go level by level with multiple proxies. I thought it was enough with one proxy to represent it in the Top-Level. Anyway, I understood all now. Thanks once again!

0 Likes
Message 6 of 7

sergio_duran
Advocate
Advocate

Hi Rocky,

One more question, do we need to create two proxies due to the SubstituteLOD part? I understand that the part is a third level and I need it to create two proxies to send it from third level to second level and from second level to first/top level. However, I've created a drawing centermark of a subassembly origin point in a third-level of the structure by only using one single proxy. The only difference is that this is a third-level subassembly placed in a subassembly (second level) of the top level assembly (first level) whereas the SubstituteLOD part is in the same level but it's used in a LOD representation. I don't know whether this makes also a difference. I'll send you a code tomorrow where I can create a centermark of third level subassembly Work Point by only using one proxy. That's why I'm confused. Although you gave me the answer tonight, I'm still confused why it works in other cases only by using one proxy.

 

Have a good night!

0 Likes
Message 7 of 7

YuhanZhang
Autodesk
Autodesk

When you create the proxy for an object in assembly you should consider the level of the occurrence, to know how many levels of an occurrence you can track the number of the ParentOccurrence till the top-assembly, below is a VBA sample to show the levels of all leaf occurrences in a top assembly:

 

Sub QueryTheLevelOfLeafOccurrence()
    Dim oTopAssy As AssemblyDocument
    Set oTopAssy = ThisApplication.ActiveDocument
    
    Dim oLeaf As ComponentOccurrence
    Dim lParentOccuCount As Long
    Dim oParent As Object, bEnd As Boolean
    
    For Each oLeaf In oTopAssy.ComponentDefinition.Occurrences.AllLeafOccurrences
        Set oParent = oLeaf.ParentOccurrence
        bEnd = False
        lParentOccuCount = 0
        
        Do
            If Not (oParent Is Nothing) Then
                lParentOccuCount = lParentOccuCount + 1
                Set oParent = oParent.ParentOccurrence
            Else
                bEnd = True
            End If
        Loop Until bEnd
        Debug.Print "The leaf occurrence: '" & oLeaf.Name & "' is  " & lParentOccuCount + 1 & "(th) level occurrence in the top assembly."
    Next
End Sub

With your attached data, open the assembly and we will get below results:

 

 

The leaf occurrence: 'box1:1' is the 2(th) level occurrence in the top assembly.
The leaf occurrence: 'box2:1' is the 2(th) level occurrence in the top assembly.
The leaf occurrence: 'SubstituteLOD part:1' is the 2(th) level occurrence in the top assembly.
The leaf occurrence: 'Cylinder:1' is the 1(th) level occurrence in the top assembly.

 

Also demonstrated as below pic:

 

OccuLevel.png

 

When you get the level of an occurrence in top assembly, you know how many times to create the proxy.  Hope this helps to understand the level of occurrence.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes