Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Turn off 2D sketch via code

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
NachitoMax
367 Views, 6 Replies

Turn off 2D sketch via code

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 Programmer (C#, VB.Net / iLogic)


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.


6 REPLIES 6
Message 2 of 7
VdVeek
in reply to: NachitoMax

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.
Message 3 of 7
GosponZ
in reply to: NachitoMax


'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 

Message 4 of 7
NachitoMax
in reply to: GosponZ

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 Programmer (C#, VB.Net / iLogic)


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 5 of 7
NachitoMax
in reply to: NachitoMax

Solution

 

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

 

Thanks

 

 

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


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
in reply to: NachitoMax

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

bdw did you see pm?

Message 7 of 7
NachitoMax
in reply to: GosponZ

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 Programmer (C#, VB.Net / iLogic)


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.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report