I am trying to add a piece of code to a drawing document that toggles the visibility of a sketch ON and OFF. I've tried a lot of variations in my code and I can't seem to get it to work. This seems like a simple code to write but I can't figure it out.
Here's the code I have: SyntaxEditor Code Snippet
Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument For Each oSketch In oDoc.ComponentDefinition.Sketches If oSketch.Name = "Sketch4" Then If iProperties.Value("Custom", "Material_Cover") = "GALV. STEEL CHECKERED COVER" Then oSketch.Visible = True Else oSketch.Visible = False End If End If Next
The error that the rule shows says: "Public member 'ComponentDefinition' on type '_DocumentClass' not found."
Solved! Go to Solution.
I am trying to add a piece of code to a drawing document that toggles the visibility of a sketch ON and OFF. I've tried a lot of variations in my code and I can't seem to get it to work. This seems like a simple code to write but I can't figure it out.
Here's the code I have: SyntaxEditor Code Snippet
Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument For Each oSketch In oDoc.ComponentDefinition.Sketches If oSketch.Name = "Sketch4" Then If iProperties.Value("Custom", "Material_Cover") = "GALV. STEEL CHECKERED COVER" Then oSketch.Visible = True Else oSketch.Visible = False End If End If Next
The error that the rule shows says: "Public member 'ComponentDefinition' on type '_DocumentClass' not found."
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Paul1084. Go to Solution.
Solved by johnsonshiue. Go to Solution.
I'm suffering with the same problem, have you found an solution already??
I'm suffering with the same problem, have you found an solution already??
Hi MarioSDiSanto and thomas.desouza,
The drawing environment is a bit different due to sheets, here's a quick example of working with the sketches in the drawing.
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oDrawDoc As DrawingDocument Dim oActiveSheet As Sheet Dim oDrawSketch As DrawingSketch oDrawDoc = ThisApplication.ActiveDocument oActiveSheet = oDrawDoc.ActiveSheet For Each oDrawingView In oActiveSheet.DrawingViews For Each oDrawingSketch In oDrawingView.Sketches 'do stuff here Next Next
Hi MarioSDiSanto and thomas.desouza,
The drawing environment is a bit different due to sheets, here's a quick example of working with the sketches in the drawing.
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oDrawDoc As DrawingDocument Dim oActiveSheet As Sheet Dim oDrawSketch As DrawingSketch oDrawDoc = ThisApplication.ActiveDocument oActiveSheet = oDrawDoc.ActiveSheet For Each oDrawingView In oActiveSheet.DrawingViews For Each oDrawingSketch In oDrawingView.Sketches 'do stuff here Next Next
Hi MarioSDiSanto and thomas.desouza,
On 2nd thought, I don't think my previous reply is not going to work. I just noticed that you can't right click and turn off the visibility of a drawing sketch.
And looking at the API it appears DrawingSketch.Visible can only be used to find the visibility of the view.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Parent Object: DrawingSketch
Property that indicates the visibility of the sketch.
DrawingSketch.Visible() As Boolean
Hi MarioSDiSanto and thomas.desouza,
On 2nd thought, I don't think my previous reply is not going to work. I just noticed that you can't right click and turn off the visibility of a drawing sketch.
And looking at the API it appears DrawingSketch.Visible can only be used to find the visibility of the view.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Parent Object: DrawingSketch
Property that indicates the visibility of the sketch.
DrawingSketch.Visible() As Boolean
Hi! Indeed, Drawing sketch is quite different from model sketch. It is actually controlled by Layer. By default, it is on "Sketch Geometry" layer. If you turn off the layer, all sketch geometry on the drawing will be invisible.
I don't know iLogic well enough to tell that if you can create a rule to control the layer. But, I think it should be possible. Would it yield the result you are looking for?
Many thanks!
Hi! Indeed, Drawing sketch is quite different from model sketch. It is actually controlled by Layer. By default, it is on "Sketch Geometry" layer. If you turn off the layer, all sketch geometry on the drawing will be invisible.
I don't know iLogic well enough to tell that if you can create a rule to control the layer. But, I think it should be possible. Would it yield the result you are looking for?
Many thanks!
Hii yesterday i've found something that might work.
But in that case the file data will be larger than the original file size.
If you insert two different drawings within an .idw drawing, you can switch between the sketches because they have become different view ports.
In order to this, I wrote the following code:
If Parameter("<drawingname>.ipt.<parameter>") = 0 mm Then ActiveSheet.View("VIEW1").View.Suppressed = True ActiveSheet.View("VIEW2").View.Suppressed = False Else If Parameter("<drawingname>.ipt.<parameter>") >= 1 mm Then ActiveSheet.View("VIEW1").View.Suppressed = False ActiveSheet.View("VIEW2").View.Suppressed = True iLogicVb.UpdateWhenDone = True End If
For me this helped me out.
The only point of criticism is that you should have to add several drawings, which makes your file (maybe) much larger then the original file size.
BTW you can also do this with assamblies.
So you can make two identical assemblies with two sketches conceived in it.
Thereon you make the first sketch visible in the assembly and the second sketch invisible.
Afterwards you do the same at assebly 2 but in opposite way.
Hope it will work for you.
Cheers,
Hii yesterday i've found something that might work.
But in that case the file data will be larger than the original file size.
If you insert two different drawings within an .idw drawing, you can switch between the sketches because they have become different view ports.
In order to this, I wrote the following code:
If Parameter("<drawingname>.ipt.<parameter>") = 0 mm Then ActiveSheet.View("VIEW1").View.Suppressed = True ActiveSheet.View("VIEW2").View.Suppressed = False Else If Parameter("<drawingname>.ipt.<parameter>") >= 1 mm Then ActiveSheet.View("VIEW1").View.Suppressed = False ActiveSheet.View("VIEW2").View.Suppressed = True iLogicVb.UpdateWhenDone = True End If
For me this helped me out.
The only point of criticism is that you should have to add several drawings, which makes your file (maybe) much larger then the original file size.
BTW you can also do this with assamblies.
So you can make two identical assemblies with two sketches conceived in it.
Thereon you make the first sketch visible in the assembly and the second sketch invisible.
Afterwards you do the same at assebly 2 but in opposite way.
Hope it will work for you.
Cheers,
Hi! Your code should work too but suppress/unsuppress sheet might take time. Here is another code from our iLogic expert.
This is assumed that Sketch Geometry layer is set to "Sketch Geometry (ANSI)." Change it according to your Object Default.
Dim oDoc As Document = ThisApplication.ActiveDocument
' Go through every sheet.
Dim oSheet As Sheet
For Each oSheet In oDoc.Sheets
oSheet.Activate()
Dim oLayers As LayersEnumerator = oSheet.Parent.StylesManager.Layers
oLayers.Item("Sketch Geometry (ANSI)").Visible= True
oLayers.Item("Sketch Geometry (ANSI)").Visible= False
oSheet.Update
Next
Let me know if it works.
Many thanks!
Hi! Your code should work too but suppress/unsuppress sheet might take time. Here is another code from our iLogic expert.
This is assumed that Sketch Geometry layer is set to "Sketch Geometry (ANSI)." Change it according to your Object Default.
Dim oDoc As Document = ThisApplication.ActiveDocument
' Go through every sheet.
Dim oSheet As Sheet
For Each oSheet In oDoc.Sheets
oSheet.Activate()
Dim oLayers As LayersEnumerator = oSheet.Parent.StylesManager.Layers
oLayers.Item("Sketch Geometry (ANSI)").Visible= True
oLayers.Item("Sketch Geometry (ANSI)").Visible= False
oSheet.Update
Next
Let me know if it works.
Many thanks!
Mario,
In the mean time, have you found a solution to change visibility of different sketches within an idw file?
Regards,
Steven
Mario,
In the mean time, have you found a solution to change visibility of different sketches within an idw file?
Regards,
Steven
Hi, You can control the include status of a sketch in an IDW... see code below:
Dim Doc As DrawingDocument Doc = ThisDoc.Document Dim oAsmDoc As AssemblyDocument Dim oCompDef As AssemblyComponentDefinition
oAsmDoc = Doc.ReferencedDocuments.Item(1)
oCompDef = oAsmDoc.ComponentDefinition ' For top level asm or ipt the below will work: Call oView(1).SetIncludeStatus(oCompDef.Sketches.Item(1), True) 'For sub Assemblies or parts, you need to create a proxy (the below code will look for all occurrences with "Example" in the file name and include the sketch named: "Example Sketch": Dim DP As ComponentOccurrence For Each DP In oCompDef.Occurrences If DP.Definition.Document.FullDocumentName.Contains("Example") Then Call DP.CreateGeometryProxy(DP.Definition.Sketches.Item("Example Sketch"), oSketchProxy) Call oView(1).SetIncludeStatus(oSketchProxy, True) End If Next
Hi, You can control the include status of a sketch in an IDW... see code below:
Dim Doc As DrawingDocument Doc = ThisDoc.Document Dim oAsmDoc As AssemblyDocument Dim oCompDef As AssemblyComponentDefinition
oAsmDoc = Doc.ReferencedDocuments.Item(1)
oCompDef = oAsmDoc.ComponentDefinition ' For top level asm or ipt the below will work: Call oView(1).SetIncludeStatus(oCompDef.Sketches.Item(1), True) 'For sub Assemblies or parts, you need to create a proxy (the below code will look for all occurrences with "Example" in the file name and include the sketch named: "Example Sketch": Dim DP As ComponentOccurrence For Each DP In oCompDef.Occurrences If DP.Definition.Document.FullDocumentName.Contains("Example") Then Call DP.CreateGeometryProxy(DP.Definition.Sketches.Item("Example Sketch"), oSketchProxy) Call oView(1).SetIncludeStatus(oSketchProxy, True) End If Next
Good afternoon,
Was this something changed in the last few years? In this thread its stated, and proved that the .visible was only a read only property. However now I'm using a sketch within a drawing as a box to place 4 views within and scale properly. This led me to this thread trying to turn the visibility of the sketch off.
However, In looking into the documentation it seems that it no longer matches what @Curtis_Waguespack has stated. Attaching a picture pulled from my documentation. Are we still going about turning off visibility in a round about way? I see that we still do not have a visible right click option?
We also have an improvement thread that got buried asking for this functionality. It seems plenty of people want access to simply turning their sketches off in the drawing environment. Is there a particular reason this has not been added? Or is there some entirely new way to access the visibility of these drawing sketches?
Good afternoon,
Was this something changed in the last few years? In this thread its stated, and proved that the .visible was only a read only property. However now I'm using a sketch within a drawing as a box to place 4 views within and scale properly. This led me to this thread trying to turn the visibility of the sketch off.
However, In looking into the documentation it seems that it no longer matches what @Curtis_Waguespack has stated. Attaching a picture pulled from my documentation. Are we still going about turning off visibility in a round about way? I see that we still do not have a visible right click option?
We also have an improvement thread that got buried asking for this functionality. It seems plenty of people want access to simply turning their sketches off in the drawing environment. Is there a particular reason this has not been added? Or is there some entirely new way to access the visibility of these drawing sketches?
@J_Pfeifer_ , I think the documentation has been updated, but is wrong.
Here are a couple of examples to do this per sketch, by pushing the sketch entities to a layer that is not visible, or visible depending upon if the sketch is to be shown.
The first does this for a sketch, for a view associated to a view:
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument oSketchName = "Sketch1" Dim oDrawingSketch As DrawingSketch oDrawingSketch = ActiveSheet.DrawingViews.ItemByName("VIEW1").NativeEntity.Sketches.Item(oSketchName) oLayerVisible = InputRadioBox("Select one:", "Sketch On", "Sketch Off", True, oSketchName & " visible state") '[get layers Dim oVisibleLayer As Layer = oDrawDoc.StylesManager.Layers.Item("Sketch Geometry(Default)") Dim oNotVisibleLayer As Layer Try oNotVisibleLayer = oVisibleLayer.Copy("Invisible Sketches") Catch oNotVisibleLayer = oDrawDoc.StylesManager.Layers.Item("Invisible Sketches") End Try oNotVisibleLayer.Visible = False '] '[edit sketch oDrawingSketch.Edit For Each oEnt As SketchEntity In oDrawingSketch.SketchEntities If oLayerVisible = False Then oEnt.Layer = oNotVisibleLayer Else oEnt.Layer = oVisibleLayer End If Next oDrawingSketch.ExitEdit ']
This 2nd example does this for a sketch that is on the sheet, and not associated to a view:
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument oSketchName = "Sketch2" Dim oDrawingSketch As DrawingSketch oDrawingSketch = ActiveSheet.NativeEntity.Sketches.Item(oSketchName) oLayerVisible = InputRadioBox("Select one:", "Sketch On", "Sketch Off", True, oSketchName & " visible state") '[get layers Dim oVisibleLayer As Layer = oDrawDoc.StylesManager.Layers.Item("Sketch Geometry(Default)") Dim oNotVisibleLayer As Layer Try oNotVisibleLayer = oVisibleLayer.Copy("Invisible Sketches") Catch oNotVisibleLayer = oDrawDoc.StylesManager.Layers.Item("Invisible Sketches") End Try oNotVisibleLayer.Visible = False '] '[edit sketch oDrawingSketch.Edit For Each oEnt As SketchEntity In oDrawingSketch.SketchEntities If oLayerVisible = False Then oEnt.Layer = oNotVisibleLayer Else oEnt.Layer = oVisibleLayer End If Next oDrawingSketch.ExitEdit ']
@J_Pfeifer_ , I think the documentation has been updated, but is wrong.
Here are a couple of examples to do this per sketch, by pushing the sketch entities to a layer that is not visible, or visible depending upon if the sketch is to be shown.
The first does this for a sketch, for a view associated to a view:
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument oSketchName = "Sketch1" Dim oDrawingSketch As DrawingSketch oDrawingSketch = ActiveSheet.DrawingViews.ItemByName("VIEW1").NativeEntity.Sketches.Item(oSketchName) oLayerVisible = InputRadioBox("Select one:", "Sketch On", "Sketch Off", True, oSketchName & " visible state") '[get layers Dim oVisibleLayer As Layer = oDrawDoc.StylesManager.Layers.Item("Sketch Geometry(Default)") Dim oNotVisibleLayer As Layer Try oNotVisibleLayer = oVisibleLayer.Copy("Invisible Sketches") Catch oNotVisibleLayer = oDrawDoc.StylesManager.Layers.Item("Invisible Sketches") End Try oNotVisibleLayer.Visible = False '] '[edit sketch oDrawingSketch.Edit For Each oEnt As SketchEntity In oDrawingSketch.SketchEntities If oLayerVisible = False Then oEnt.Layer = oNotVisibleLayer Else oEnt.Layer = oVisibleLayer End If Next oDrawingSketch.ExitEdit ']
This 2nd example does this for a sketch that is on the sheet, and not associated to a view:
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument oSketchName = "Sketch2" Dim oDrawingSketch As DrawingSketch oDrawingSketch = ActiveSheet.NativeEntity.Sketches.Item(oSketchName) oLayerVisible = InputRadioBox("Select one:", "Sketch On", "Sketch Off", True, oSketchName & " visible state") '[get layers Dim oVisibleLayer As Layer = oDrawDoc.StylesManager.Layers.Item("Sketch Geometry(Default)") Dim oNotVisibleLayer As Layer Try oNotVisibleLayer = oVisibleLayer.Copy("Invisible Sketches") Catch oNotVisibleLayer = oDrawDoc.StylesManager.Layers.Item("Invisible Sketches") End Try oNotVisibleLayer.Visible = False '] '[edit sketch oDrawingSketch.Edit For Each oEnt As SketchEntity In oDrawingSketch.SketchEntities If oLayerVisible = False Then oEnt.Layer = oNotVisibleLayer Else oEnt.Layer = oVisibleLayer End If Next oDrawingSketch.ExitEdit ']
Can't find what you're looking for? Ask the community or share your knowledge.