Autodesk Inventor
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello,
As we have layers in AutoCAD Product, I Started using different sketches and using them as layers by turning the visibility on and off.
Can we write a macro (button Click) to turn one perticular Sketch on and off???
For example If I had a Sketch named as GROUNDFLOOR, can I use a macro to turn them off and on when needed??
Thanks
AD
Inventor Applications Engineer
--------------------------------------------------------------------------------------
If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -
-------------------------------------------------------------------------------------
Solved! Go to Solution.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi AD,
Contact with API expert Jane, it possiblly to add an VBA/VB code to turn on/off the visibility of perticular Sketch, but for button provided, need more consideration.
Xun

Xun Zhang
Software QA Engineer
Inventor Quality Assurance Team
Autodesk, Inc.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello,
How about runt he macro in VBA?
Sub test()
Call SetVisible(True)
End Sub
Sub SetVisible(bFlag)
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oSks As PlanarSketches
Set oSks = oDoc.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch
For Each oSketch In oSks
If oSketch.Name = "GROUNDSketch" Or oSketch.Name = "What I Need else" Then
oSketch.Visible = bFlag
End If
Next
End Sub
Software QA Engineer
Inventor Quality Assurance Team
Autodesk, Inc.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Inventor Applications Engineer
--------------------------------------------------------------------------------------
If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -
-------------------------------------------------------------------------------------
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Please make sure the sketch name is what you want to turn off/on in the code line below
If oSketch.Name = "GROUNDSketch" Or oSketch.Name = "What I Need else" Then
oSketch.Visible = bFlag
End If
And I think you could also use the "find button" on the top of inventor browser panel to get the right sketch, and turn on/off its visibility. Please see the attached image.
River Cai
Quality Assurance Team
Autodesk, Inc.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Xun.Zhang
Sure, i will contact and thanks for reply
AD
Inventor Applications Engineer
--------------------------------------------------------------------------------------
If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -
-------------------------------------------------------------------------------------
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
hello River,
I tried tried and tried to fix that error and it is saying as missmatch error.
Included picture if what I am doing.
If you know something abt it let me know
Thanks
Inventor Applications Engineer
--------------------------------------------------------------------------------------
If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -
-------------------------------------------------------------------------------------
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Based on the error in the image, it looks that you want to use this macro in assembly document. But the macro you used is only for part document. If you want to use the macro for assembly document, we should refine the macro to accomplish it.
River Cai
Quality Assurance Team
Autodesk, Inc.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi AD,
I guess you opened an assembly document, instead of part document. to make the code supports all types of document, please change the document type to Document instead of PartDocument. Use following code instead to have a try:
Sub test()
Call SetVisible(True)
End Sub
Sub SetVisible(bFlag)
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oSks As PlanarSketches
Set oSks = oDoc.ComponentDefinition.Sketches
Dim oSketch As PlanarSketch
For Each oSketch In oSks
If oSketch.Name = "GROUNDSketch" Or oSketch.Name = "What I Need else" Then
oSketch.Visible = bFlag
End If
Next
End Sub
Software QA Engineer
Inventor Quality Assurance Team
Autodesk, Inc.
Re: Macro to turn visibility for particular Sketch
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
And there is another comments:
If you want to change the visibllity staus of the sketches in assembly document, they the code above works.
But it won't work on the sketches of assembly occurrences. It will work in this way if you want to change the sketch status in assembly occurrences:
Sub Test()
'Input True or False
Call ChangeVisiblityOfAssySketch(True)
End Sub
Sub ChangeVisiblityOfAssySketch(bFlag)
Dim odoc As AssemblyDocument
Set odoc = ThisApplication.ActiveDocument
Dim i As Integer
Dim oSk As PlanarSketch
For i = 1 To odoc.ComponentDefinition.Occurrences.Count
For Each oSk In odoc.ComponentDefinition.Occurrences
If oSk.Name = "What you need" Then
oSk.Visible = bFlag
Exit For
End If
Next
Next
End Sub
Software QA Engineer
Inventor Quality Assurance Team
Autodesk, Inc.



