Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Show hide Assembly sketches on a drawing (IDW)

m.verbunt
Advocate

Show hide Assembly sketches on a drawing (IDW)

m.verbunt
Advocate
Advocate

Hello all,

 

I am struggling to find the right way to get this iLogic code write. I did search a lot for some examples but none pointed me in the right direction. So hopefully someone here can help me out.

 

I have made an Assembly of a swimming pool. In this assembly I have created different sketches to represent possible plumbing setups. These sketches are at the top level of the assembly, so they are not part of any occurrences.

 

When in the drawing with the model selected, I can select 'Get Model Sketches'. Having done that the Assembly sketches become available in the drawing, and 'Include' will show the sketch in the drawing view.

 

No, I have eight possible sketches available:

 

Sketch 1a

Sketch 2a

Sketch 3a

Sketch 4a

Sketch 1b

Sketch 2b

Sketch 3c

Sketch 4c

 

The challenge I face is this: I want to in or exclude these sketches by use of iLogic. I can access the controlling parameter "Connection Point" from the assembly. These contain the eight options. I want iLogic to show the corresponding sketch in my drawing view which is on sheet "Customer" on "View1".

 

How can I achieve this? Any help would be greatly appreciated!

 

 

0 Likes
Reply
415 Views
4 Replies
Replies (4)

A.Acheson
Mentor
Mentor

Hi @m.verbunt 

 

From this article which is actually for sub assemblies try this out. The sub assembly looping is removed and no need for proxy sketches. All sketches will be shown so you need to build in the logic for which sketch to show when.

 

        Dim oDrawingDoc As DrawingDocument

        If ThisApplication.ActiveDocument.DocumentType <>

           kDrawingDocumentObject Then

            MsgBox("need to make a drawing the active document")
        End If

        oDrawingDoc = ThisApplication.ActiveDocument

        Dim oView As DrawingView

        If oDrawingDoc.ActiveSheet.DrawingViews.Count < 1 Then

            MsgBox("Add a view to the drawing")
        Return
        End If

        oView = oDrawingDoc.ActiveSheet.DrawingViews(1)
        Dim oDoc As Document
        oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

        If oDoc.DocumentType <> kAssemblyDocumentObject Then

            MsgBox("View's Referenced doc needs to be an assembly")
        End If

        Dim oAssy As AssemblyDocument

        oAssy = oView.ReferencedDocumentDescriptor.ReferencedDocument
 
        Dim oAssyDef As AssemblyComponentDefinition

        oAssyDef = oAssy.ComponentDefinition

        Logger.Info(oAssyDef.Sketches.Count)
        
        Dim oSketch As PlanarSketch     
        For Each oSketch In oAssyDef.Sketches
           oView.SetVisibility(oSketch, True)
         Next

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

m.verbunt
Advocate
Advocate

Hi! Thanks for the quick repley. I will try this, and let you know the results.

 

Many thanks for taking the time to help me out. It's much appriciated!

0 Likes

m.verbunt
Advocate
Advocate

Hi,

 

This doesn't seem to be working unfortunately. So I turned to ChatGPT to see if I could generate some code to push me in the correct direction. It looks like it got me pretty far, but there seems to be an error in line 25.

 

A bit more clarification about what I am trying to achieve.

 

I have an assembly with a swimming pool in it. At the top level of the assembly I have created eight sketches that represent the plumbing for different options. Our customers can chose at which corner the connection point (CP) will be located, and optionally we have a an extra option for each of those connection points.

 

The assembly holds the following parameters:

“ConnectionPoint” as a text parameter (CP1, CP2, CP3, CP4)

“Engels” as a Boolean parameter (True, False)

 

The sketches are:

“CP1“

“CP2“

“CP3“

“CP4“

“CP1 Engels“

“CP2 Engels“

“CP3 Engels“

“CP4 Engels“

 

Based on the selection of these parameters the correct sketch must been shown on the drawing (idw), the other sketches that do not correspond to these parameters need to be hidden.

In the drawing these sketches are already made available in the correct view. (“Get Model sketches”). Manually, I can include or exclude the sketches, but I would like iLogic to take care of this.  

The sheet name of the drawing (idw) where the sketches must be made visible is “Customer:1” and the view name is “VIEW1”.

 

 

 

 

    Dim drawingDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim sheet As Sheet = drawingDoc.Sheets.Item("Customer:1") ' Replace "Customer:1" with the actual sheet name
    Dim view As DrawingView = Nothing

    For Each drawingView As DrawingView In sheet.DrawingViews
        If DrawingView.Name = "VIEW1" Then ' Replace "VIEW1" with the actual view name
            view = DrawingView
            Exit For
        End If
    Next

    If view IsNot Nothing Then
        Dim asmDoc As AssemblyDocument = TryCast(view.ReferencedDocumentDescriptor.ReferencedDocument, AssemblyDocument)

        If asmDoc IsNot Nothing Then
            Dim asmCompDef As ComponentDefinition = asmDoc.ComponentDefinition
            Dim connectionPoint As String = asmCompDef.Parameters.Item("ConnectionPoint").Value
            Dim engels As Boolean = asmCompDef.Parameters.Item("Engels").Value

            Dim sketchName As String = connectionPoint
            If engels Then
                sketchName = sketchName & " Engels"
            End If

            For Each sketch As Sketch In asmDoc.Sketches
                If Sketch.Name = sketchName Then
                    view.SetVisibility(sketchName, True)
                Else
                    view.SetVisibility(sketchName, False)
                End If
            Next
        End If
    End If

 

 

Any idea, how to fix this?

0 Likes

A.Acheson
Mentor
Mentor

Line 25 the assembly document does not contain the sketches collection. This is contained in the assembly component definition. The error message you would have received in the more info tab would likely have diagnosed this. 

See the API help for AssemblyComponentDefintion.sketches property 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes