Turn off 2D sketch via code

Turn off 2D sketch via code

NachoShaw
Advisor Advisor
645 Views
6 Replies
Message 1 of 7

Turn off 2D sketch via code

NachoShaw
Advisor
Advisor

Hi

 

how can i turn off the 2D sketch on an assembly just like the clicking of the tick box in Views?

 

2d sketch.JPG

 

need to turn this off for every assembly i open automatically. Can it be done?

 

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


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

VdVeek
Advocate
Advocate

I think it's a much better way to set the visibility of all the sketches in all parts to unvisible instead of turning the visibility off by the "Object Visibility" Command. I use a VBA-script to switch the visibility of each sketch in an assembly. You can test this script, but at large assemblies it can take some time. See attachment for the VBA-script.

 

Rob.

Autodesk Inventor 2015 Certified Professional & Autodesk Inventor 2012 Certified Professional.
0 Likes
Message 3 of 7

GosponZ
Collaborator
Collaborator

'Attribute VB_Name = "Hide_Sketches_And_planes" Sub Hide_Sketches_And_planes() 'catch and skip errors On Error Resume Next ' Get the active document. Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc.DocumentType = kAssemblyDocumentObject Then Call HideAssemblyComponents ElseIf oDoc.DocumentType = kPartDocumentObject Then Call HidePartComponents Else MsgBox ("The active file is no assembly or part. Script can't be used here.") Exit Sub End If End Sub Private Sub HideAssemblyComponents() Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument 'get user input as True or False Dim Vis As Boolean Dim result result = MsgBox("Hide all sketches and workplanes?" & vbCrLf & vbCrLf & "Click Yes to hide all sketches and workplanes." & vbCrLf & "Click No to Show all sketches and worplanes.", vbYesNoCancel) Select Case result Case vbYes Vis = False Case vbNo Vis = True Case vbCancel Exit Sub End Select 'catch and skip errors On Error Resume Next Dim oSetch As PlanarSketch Dim oWorkPlane As WorkPlane Dim oDoc As Inventor.Document 'Iterate tru all referenced documents and change visibility For Each oDoc In oAsmDoc.AllReferencedDocuments For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes oWorkPlane.Visible = Vis Next 'set work axis visibility For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes oWorkAxis.Visible = Vis Next 'set work point visibility For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints oWorkPoint.Visible = Vis Next For Each oSketch In oDoc.ComponentDefinition.Sketches oSketch.Visible = Vis Next Next 'change visibility from active assembly document For Each oWorkPlane In oAsmDoc.ComponentDefinition.WorkPlanes oWorkPlane.Visible = Vis Next 'set work axis visibility For Each oWorkAxis In oAsmDoc.ComponentDefinition.WorkAxes oWorkAxis.Visible = Vis Next 'set work point visibility For Each oWorkPoint In oAsmDoc.ComponentDefinition.WorkPoints oWorkPoint.Visible = Vis Next For Each oSketch In oAsmDoc.ComponentDefinition.Sketches oSketch.Visible = Vis Next ThisApplication.ActiveDocument.Update End Sub Private Sub HidePartComponents() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument 'get user input as True or False Dim Vis As Boolean Dim result result = MsgBox("Hide all sketches and workplanes?" & vbCrLf & vbCrLf & "Click Yes to hide all sketches and workplanes." & vbCrLf & "Click No to Show all sketches and worplanes.", vbYesNoCancel) Select Case result Case vbYes Vis = False Case vbNo Vis = True Case vbCancel Exit Sub End Select Dim oSetch As PlanarSketch Dim oWorkPlane As WorkPlane Dim oDoc As Inventor.Document 'change visibility from active part document For Each oWorkPlane In oPartDoc.ComponentDefinition.WorkPlanes oWorkPlane.Visible = Vis Next 'set work axis visibility For Each oWorkAxis In oPartDoc.ComponentDefinition.WorkAxes oWorkAxis.Visible = Vis Next 'set work point visibility For Each oWorkPoint In oPartDoc.ComponentDefinition.WorkPoints oWorkPoint.Visible = Vis Next For Each oSketch In oPartDoc.ComponentDefinition.Sketches oSketch.Visible = Vis Next ThisApplication.ActiveDocument.Update End Sub

Working for me 

0 Likes
Message 4 of 7

NachoShaw
Advisor
Advisor

Hi

 

thanks for the replies and hte code. The routine does create a very large lag (my assemblies are large) and also, it doesnt turn off the 2D sketches. Isnt there a similar function the check box that we tick to turn everything off?

 

i'll take a look 🙂

 

 

 

 

Cheers

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 5 of 7

NachoShaw
Advisor
Advisor
Accepted solution

Solution

 

Dim oDoc as Inventor.Document = _invApp.ActiveDocument
oDoc.ObjectVisibility.Sketches = False

 

Thanks

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 6 of 7

GosponZ
Collaborator
Collaborator

Nice stuff on this link http://www.kwikmcad.com/icode/macros/macros.aspx

bdw did you see pm?

0 Likes
Message 7 of 7

NachoShaw
Advisor
Advisor

Hi

 

Yes i saw the PM :). The tools will be on the App store as soon as i get the time to get them completed. Drawing tool first hopefully within the next 2 months.

 

 

Cheers

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes