iLogic to turn off ALL sketches vibibility

iLogic to turn off ALL sketches vibibility

Anonymous
Not applicable
3,794 Views
11 Replies
Message 1 of 12

iLogic to turn off ALL sketches vibibility

Anonymous
Not applicable

Hi,

 

I know this subject as been posted often but I can't seem to find exactly what i'm looking for.

 

I need some help on creating an iLogic code to put ALL sketches visibility at off in an assembly once we are done. I know that ALL is a concept too large but can I define a list of sketch names? We have establish (sort of) a naming convention for principal sketches but I'm sure users can reverse words or use capital letters or what ever... Can I say to look for skecthes containing certain words or I need to be specific for the rule to work properly?

 

I found useful threads but I don't know how to adapt the code for my needs.

 

Thanks,

 

 

 

0 Likes
Accepted solutions (2)
3,795 Views
11 Replies
Replies (11)
Message 2 of 12

mdavis22569
Mentor
Mentor
I don't know the code for it ...however You know you can go right to View, Object Visibility and click all work features and that'll do it too

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------
Mike Davis

EESignature

0 Likes
Message 3 of 12

Curtis_W
Consultant
Consultant

@Anonymous wrote:
I don't know the code for it ...however You know you can go right to View, Object Visibility and click all work features and that'll do it too

Hi michaeldavis7418,

 

Just a reminder that using the View >  Object Visibility option sets an override, but does not actually toggle the sketch visibiltiy on/off option.

 


 Josy05,

I'll look for some iLogic code to do this later, when I have a moment.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 4 of 12

Curtis_W
Consultant
Consultant
Accepted solution

Hi  Josy0, 

 

Here is the iLogic code to turn off the visibility of all the 2D sketches in the part:

 

Dim doc As PartDocument
doc = ThisDoc.Document

Dim oSketch As PlanarSketch
For Each oSketch In doc.ComponentDefinition.Sketches
oSketch.Visible = False 
Next

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 5 of 12

Anonymous
Not applicable

Thanks Curtis, your version of the code is simpler and works perfectly.

 

At first I thought of adding a message box to warn the users then I said why not give the choice. Is that possible? Can I have active button permitting the users not to close the sketch visibility is they desire? Because at the moment Yes or No does no make a difference, the sketches will turn off anyway.

 

 

0 Likes
Message 6 of 12

Anonymous
Not applicable
I found it on my own and the answer was on your blog.

0 Likes
Message 7 of 12

DClunie
Contributor
Contributor

Will this code work at assembly level.

 

Can it switch off on all parts found ??

0 Likes
Message 8 of 12

darrell.wcd
Enthusiast
Enthusiast

is it possible to do this from an assembly level?

that way i can create a trigger that will turn the sketches in all parts off.

0 Likes
Message 9 of 12

johnsonshiue
Community Manager
Community Manager

Hi! Just in case you were not aware of Object Visibility. You can go to View -> Object Visibility -> turn off all objects at the assembly level. Please note that the change only applies to the the assembly. The objects may still be visible within their documents or other documents.

Many thanks!



Johnson Shiue ([email protected])
Software Test Engineer
0 Likes
Message 10 of 12

aniketpunwatkar
Participant
Participant
Accepted solution

Hello,

           I have worked on this code works super fine.

Don't need high end logic or complex code.it is as simple as poem to read

 

 
Dim doc As AssemblyDocument
 doc = ThisApplication.ActiveDocument

If Not doc Is Nothing Then

Dim asmCompDef As AssemblyComponentDefinition
asmCompDef=doc.ComponentDefinition

Dim comp As ComponentOccurrence
For Each comp In asmCompDef.Occurrences.AllLeafOccurrences
	
	
If comp.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	
		
Dim compDef As PartComponentDefinition
comDef = comp.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition


		
Dim sw As Inventor.Sketch
For Each sw In comDef.Sketches
	sw.Visible = Not sw.Visible
Next sw



Dim wp As WorkPoint
For Each wp In comDef.WorkPoints
	wp.Visible = Not wp.Visible
Next wp
	
Dim pl As WorkPlane
For Each pl In comDef.WorkPlanes
	pl.Visible = Not pl.Visible
Next pl

End If
	
Next comp

End If
	
	
Message 11 of 12

nathan_m_gardner
Enthusiast
Enthusiast

I get this error message when I run this code. I have colored the line it errors out on.

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Sketch.set_Visible(Boolean )
at ThisRule.Main() in rule: test, in document 335850.iam:line 23
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

Dim doc As AssemblyDocument
 doc = ThisApplication.ActiveDocument

If Not doc Is Nothing Then

Dim asmCompDef As AssemblyComponentDefinition
asmCompDef=doc.ComponentDefinition

Dim comp As ComponentOccurrence
For Each comp In asmCompDef.Occurrences.AllLeafOccurrences
	
	
If comp.ReferencedDocumentDescriptor.ReferencedDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	
		
Dim compDef As PartComponentDefinition
comDef = comp.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition


		
Dim sw As Inventor.Sketch
For Each sw In comDef.Sketches
	sw.Visible = Not sw.Visible
Next sw



Dim wp As WorkPoint
For Each wp In comDef.WorkPoints
	wp.Visible = Not wp.Visible
Next wp
	
Dim pl As WorkPlane
For Each pl In comDef.WorkPlanes
	pl.Visible = Not pl.Visible
Next pl

End If
	
Next comp

End If

 I have colored  

0 Likes
Message 12 of 12

WCrihfield
Mentor
Mentor

Hi @nathan_m_gardner.  You may have to get a reference to the Document object that the leaf occurrence is referencing, then check its Document.IsModifiable property first.  If its value is False, then skip that one, because you will not be able to make changes to it.  Then, only if its value is True, access its ComponentDefinition, then the visibility settings.  Just one possibility.  Content Center stuff, as well as any models referencing files that are located in a 'Library' location, are usually ReadOnly, but those are not the only ones.  Sometimes having multiple ModelStates in referenced model files, then including multiple ModelState versions of that model in an assembly as different components can cause them to be treated as ReadOnly, because it thinks they are 'ModelState members' instead of 'a ModelState factory'.  We can only write to one ModelState representation of a model file at a time, so when multiple versions are open at the same time, because they are being referenced by open assemblies or drawings, that can cause complex issues.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes