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: 

Changing Sketch Visibility in a Drawing Document using ILogic

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Anonymous
2766 Views, 12 Replies

Changing Sketch Visibility in a Drawing Document using ILogic

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."

12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

I'm suffering with the same problem, have you found an solution already??

Message 3 of 13
Curtis_Waguespack
in reply to: Anonymous

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
Message 4 of 13

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

 

DrawingSketch.Visible Property

Parent Object: DrawingSketch

 

Description

Property that indicates the visibility of the sketch.

 

Syntax

DrawingSketch.Visible() As Boolean

 

 

 

 

Message 5 of 13
Anonymous
in reply to: Anonymous

Unfortunately I have not found a solution. I don't think it is possible to toggle the visibility of a sketch in a drawing.
Message 6 of 13
johnsonshiue
in reply to: Anonymous

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!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 7 of 13
Anonymous
in reply to: johnsonshiue

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.

This is possible, for example, when there is a certain value variable in the parameters of the .ipt drawing(s).

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,

 

 

Message 8 of 13
johnsonshiue
in reply to: Anonymous

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!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 9 of 13
Anonymous
in reply to: johnsonshiue

Yes this code works well. I just got a find a way to switch the layer of some sketches because I have four separate sketches in my drawing and I only want to suppress one of the at a time.

Your code pushed me into the right direction though, thanks.
Message 10 of 13
Anonymous
in reply to: Anonymous

Mario,

 

In the mean time, have you found a solution to change visibility of different sketches within an idw file?

 

Regards,

 

Steven

Message 11 of 13
Paul1084
in reply to: Anonymous

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
Message 12 of 13

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?

 

@johnsonshiue 

Message 13 of 13
Curtis_Waguespack
in reply to: Anonymous

@Jpfeifer5TC7R ,  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:

 

Curtis_Waguespack_0-1718833181810.png

 

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:

 

Curtis_Waguespack_0-1718888882102.png

 

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.

Post to forums  

Autodesk Design & Make Report