ilogic turn sketch visibillity on or off in subassembly

ilogic turn sketch visibillity on or off in subassembly

Anonymous
Not applicable
958 Views
12 Replies
Message 1 of 13

ilogic turn sketch visibillity on or off in subassembly

Anonymous
Not applicable

Hello

I need help with iLogic.

I have an assembly with other subassemblys, parts and virtual parts in it.
In the subassemblys are sketches without extrusion. The sketches are called "Positioning".
In the sketch are gemoetries from the Subassembly for a machine. I need them for a drawing.

With the code below, I create a new view (called "Positions") in the mainasssembly and set all parts in it invisible, if the assembly is named "Machinepart".
Now I need to set only the sketches in subassembly with the name "Positioning" as visible in the view "Positions".

For information, I am not a programmer! I found some of the code below and edited it. My programming skill is on basic. If then else... thats it.

Dim Doc As Document
Doc = ThisApplication.ActiveDocument
If Doc.DisplayName = "Machinepart" Then

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oViewRep As DesignViewRepresentation

For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
    If oViewRep.Name = "Hauptansicht"  Then
    oViewRep.Activate
    'wenn Hauptansicht aktiv, skip Error
    On Error Resume Next
    Else If oViewRep.Name = "Positions"  Then
    'Ansicht löschen
    oViewRep.Delete
    Else
    End If
Next

oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Positions")      

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
  oOccurrence.Visible = False
 
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then

InventorVb.DocumentUpdate()
Else
End If
Next

For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
If oViewRep.Name = "Standard"  Then
oViewRep.Activate
On Error Resume Next
Else
End If
Next

Else
End If 

 

0 Likes
Accepted solutions (1)
959 Views
12 Replies
Replies (12)
Message 2 of 13

Owner2229
Advisor
Advisor

Hey, try this:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DisplayName <> "Machinepart" Then Exit Sub

Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oDVR As DesignViewRepresentations = oACD.RepresentationsManager.DesignViewRepresentations
Dim oVR_Positions As DesignViewRepresentation = oDVR.Item("Positions")
If oVR_Positions IsNot Nothing Then oVR_Positions.Delete()
Dim oVR_Hauptansicht As DesignViewRepresentation = oDVR.Item("Hauptansicht")
If oVR_Hauptansicht Is Nothing Then Exit Sub
Try
    oVR_Hauptansicht.Activate()
Catch
End Try

oVR_Positions = oDVR.Add("Positions")

For Each oOcc As ComponentOccurrence In oACD.Occurrences
    oOcc.Visible = False
    If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
    Dim oSubDoc As Document = oOcc.Definition.Document
    oSubDoc.Update()
    If oSubDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
    For Each oSketch As PlanarSketch In oSubDoc.ComponentDefinition.Sketches
        oSketch.Visible = (oSketch.Name = "Positioning")
    Next
Next

Dim oVR_Standard As DesignViewRepresentation = oDVR.Item("Standard")
Try
    oVR_Standard.Activate
Catch
End Try
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 13

Anonymous
Not applicable

Doesnt work. Sketch still not visible. And if no view exist with name Positions, an error occured.

In the Screenshot I show what I need.

Assembly is "Machinepart".
In every subassembly (Part1, Part2, Part3 and so on) is a sketch with name "Position".
My rule create the view "Position" if not exist and turn all Parts (1, 2, 3, ...) invisible.
The next step ist that the sketch "Position" have to be visible. But only the sketch. Not extrusions or anything else. Only the sketches with name "Positon" (arrow marker) in every part.

visible.png

visible_true.png

 

 

 

 

0 Likes
Message 4 of 13

Owner2229
Advisor
Advisor

It is not exactly what you want, but I guess it'll do. Give it a try.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DisplayName <> "Machinepart" Then Exit Sub

Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oDVR As DesignViewRepresentations = oACD.RepresentationsManager.DesignViewRepresentations
Dim oVR As DesignViewRepresentation = oDVR.Item("Positions")
If oVR IsNot Nothing Then
    Try
        oVR.Delete()
    Catch
    End Try
End If
Dim oVR_Hauptansicht As DesignViewRepresentation = oDVR.Item("Hauptansicht")
If oVR_Hauptansicht Is Nothing Then Exit Sub
Try
    oVR_Hauptansicht.Activate()
Catch
End Try
oVR = oDVR.Add("Positions")
oVR.HideAll()
Dim oShow As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection() Dim oHide As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection() For Each oOcc As ComponentOccurrence In oACD.Occurrences oOcc.Visible = False If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For Dim oSubDoc As Document = oOcc.Definition.Document oSubDoc.Update() If oSubDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For For Each oSketch As PlanarSketch In oSubDoc.ComponentDefinition.Sketches If oSketch.Name <> "Positioning" Then Continue For oShow.Add(oOcc) For Each oOcb As ComponentOccurrence In oOcc.SubOccurrences oHide.Add(oOcb) Next Next Next oVR.SetVisibilityOfOccurrences(oShow, True) oVR.SetVisibilityOfOccurrences(oHide, False) Dim oVR_Standard As DesignViewRepresentation = oDVR.Item("Standard") Try oVR_Standard.Activate Catch End Try 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 13

Anonymous
Not applicable

First I want to thank you for your help.

I think you have the same problem as I had? It isnt possible to catch the sketch direktly and turn it visible or invisible. Correct?

Because with the methode you made, I get the sketch. But all of it. The drawed lines and the projected geometries of the part.

If I turn the sketch manuelly visible, it only shows the drawn lines without projected geometries taken from the part.
Thats a problem for the machine. The machine doesnt understand different types of lines. Its all one type for it and would try to take them all.

Thats why I need only the drawn lines and why I made a extra sketch for it. 😕

 

Next problem. It doesnt take only "Position". It take all sketches in the subassembly without extrusion.
Position, Sketch2, Sketch3... in example.

 

Its annoying... 😞


Maybe, if it isnt possible in the assembly, it is in the drawing? (show "Modell sketches")


https://forums.autodesk.com/t5/inventor-forum/ilogic-rule-to-show-named-part-sketches-in-an-idw/td-p...

 

idw-visible.png

 

 

 

 

0 Likes
Message 6 of 13

Owner2229
Advisor
Advisor

I've digged a little deeper and this is probably the closest I can get you to what you want.

As you said, the problem is in making the sketch directly visible. There'll probably be a command for it in command manager, but to find that command you'll need someone from @Anonymous. Anyway, the drawing might do the trick.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DisplayName <> "Machinepart" Then Exit Sub

Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oDVR As DesignViewRepresentations = oACD.RepresentationsManager.DesignViewRepresentations
Try
    oDVR.Item("Positions").Delete()
Catch
End Try
Try
    oDVR.Item("Hauptansicht").Activate()
Catch
End Try

Dim oVR As DesignViewRepresentation = oDVR.Add("Positions")

For Each oOcc As ComponentOccurrence In oACD.Occurrences
    oOcc.Visible = False
    If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
    Dim oSubDoc As Document = oOcc.Definition.Document
    oSubDoc.Update()
    If oSubDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
    For Each oSketch As PlanarSketch In oSubDoc.ComponentDefinition.Sketches
        oSketch.Visible = False
        If Not oSketch.Name.StartsWith("Position") Then Continue For
        oSketch.Visible = True
        oOcc.Visible = True
For Each oSE As SketchEntity In oSketch.SketchEntities
If oSE.Reference Then oSE.SketchOnly = True
Next For Each oOcb As ComponentOccurrence In oOcc.SubOccurrences oOcb.Visible = False Next Next Next Try oDVR.Item("Standard").Activate Catch End Try
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 7 of 13

Anonymous
Not applicable

With the last code I get this

 

System.Runtime.InteropServices.COMException (0x80004005): Das Objekt mit dem Typ "System.__ComObject" kann nicht in den Typ "Inventor.ComponentOccurrence" konvertiert werden.
   bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   bei Inventor.SketchEntity.set_SketchOnly(Boolean )
   bei LmiRuleScript.Main()
   bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 8 of 13

Owner2229
Advisor
Advisor

Apparently the SketchEntities can't be SketchOnly after all... Atleast we can change them to "construction"... The correction:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DisplayName <> "Machinepart" Then Exit Sub

Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oDVR As DesignViewRepresentations = oACD.RepresentationsManager.DesignViewRepresentations
Try
    oDVR.Item("Positions").Delete()
Catch
End Try
Try
    oDVR.Item("Hauptansicht").Activate()
Catch
End Try

Dim oVR As DesignViewRepresentation = oDVR.Add("Positions")

For Each oOcc As ComponentOccurrence In oACD.Occurrences
    oOcc.Visible = False
    If TypeOf oOcc.Definition Is VirtualComponentDefinition Then Continue For
    Dim oSubDoc As Document = oOcc.Definition.Document
    oSubDoc.Update()
    If oSubDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
    For Each oSketch As PlanarSketch In oSubDoc.ComponentDefinition.Sketches
        oSketch.Visible = False
        If Not oSketch.Name.StartsWith("Position") Then Continue For
        oSketch.Visible = True
        oOcc.Visible = True
        For Each oSE As SketchEntity In oSketch.SketchEntities
            Try
If oSE.Reference Then oSE.Construction = True
Catch
End Try Next For Each oOcb As ComponentOccurrence In oOcc.SubOccurrences oOcb.Visible = False Next Next Next Try oDVR.Item("Standard").Activate Catch End Try
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 9 of 13

Anonymous
Not applicable

Thanks, but its the same problem.
It includes all sketches. We have to machines. One need positions 1 and the other position 2. In all parts are two sketches for both. With your code, all sketches are visible. Not only the one called position. Thats why I need only the "Position" sketches.
But I thank you very mutch for your help and the realy good try. Its a step forward.
Maybe AutoDesk Support knews a way to catch and activate visibility for sketch.
VB is possible, too... I will search try it a little bit more.

0 Likes
Message 10 of 13

Owner2229
Advisor
Advisor

I've tested it on some assemblies and only the sketch named "Positioning" was visible.

There's something strange going on...

Maybe you mean the referenced lines IN the sketch?

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 11 of 13

Anonymous
Not applicable

As you can see on picture in post 5 we have two sketches in the subassembly.
Position and Bottero.
Only Position have to be visible. With the code your provided, both sketches are included.

0 Likes
Message 12 of 13

Owner2229
Advisor
Advisor

Oh, I see now. It looks like it can't be controlled this way at all.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 13 of 13

Anonymous
Not applicable
Accepted solution

I resolved the Problem. Did the activation of the sketchs now in the drawing.

THX for the help!

0 Likes