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: 

iLogic - turn visiblity off for Sub Assembly and Part Sketches

1 REPLY 1
Reply
Message 1 of 2
vince480
1677 Views, 1 Reply

iLogic - turn visiblity off for Sub Assembly and Part Sketches

Hi All

 

I've been using some code from Curtis blog:

 

http://inventortrenches.blogspot.co.uk/2013/03/turn-onoff-all-workfeatures-with-ilogic.html

 

Great little tip and has got me into using iLogic!

 

I'm trying to expand on this.

 

I'm working in the Assembly level of a large model creating Assembly level features. Unfortunately I have the odd work feature or sketch in lower sub assemblies and parts which have mistakenly been left visible. I would like to loop through all the lower sub assemblies and parts to turn the visibility off for these.

 

The thing which has got me stuck at present, is the view reps! Some of the view reps are on "Master"and thus locked, so my code can't change the visibility of the sketch.

 

Any help would be great folks!

 

What I have so far (using Curtis example, thx)

 

' set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'define the Component Occurrence collection
Dim oCompOcc As Inventor.ComponentOccurrence 

'This assumes an assembly document is open.
'define the active assembly.
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

'create a list to hold the different options.
Dim myArrayList As New ArrayList

'add the occurrence name to the list
myArrayList.add("WorkPlanes")
myArrayList.add("WorkAxes")
myArrayList.add("WorkPoints")
myArrayList.add("Sketches")
myArrayList.add("ALL Work Features")

'present the user with the list to choose from.
myComponent = InputListBox("Select an Option."& vbLf & "This will turn visibility OFF for all nested work features.", myArrayList, myArrayList.item(0), "iLogic", "List")

'define the Design View Rep
Dim oViewRep As DesignViewRepresentation

If myComponent <> "" Then
'set the top view rep to "default". If view rep is on "Master", this is locked and visibility changes wont take effect.
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
	oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
Next
End If

'Check all referenced docs 
Dim oDoc As Inventor.Document

For Each oDoc In oAssyDoc.AllReferencedDocuments

	If myComponent = "WorkPlanes" Then
		'set work plane visibility
		For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
		oWorkPlane.Visible = False
		Next
	Else If myComponent = "WorkAxes" Then
			'set work axis visibility
			For Each oWorkAxes In oDoc.ComponentDefinition.WorkAxes
			oWorkAxes.Visible = False
			Next
	Else If myComponent = "WorkPoints" Then
			'set work point visibility
			For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
			oWorkPoint.Visible = False
			Next
	Else If myComponent = "Sketches" Then 
			'set sketch visibility
			For Each oSketch In oDoc.ComponentDefinition.Sketches
			oSketch.Visible = False
			Next
	Else If myComponent = "ALL Work Features" Then
			'Set work plane visibility
			For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
			oWorkPlane.Visible = False
			Next
			'set work axis visibility
			For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
			oWorkAxis.Visible = False
			Next
			'set work point visibility
			For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
			oWorkPoint.Visible = False
			Next
			'set sketch visibility
			For Each oSketch In oDoc.ComponentDefinition.Sketches
			oSketch.Visible = False
			Next
	End If
Next
'update the files
InventorVb.DocumentUpdate() 


'report the result
If myComponent = "" Then
MessageBox.Show("Cancelled, no work feature visibilities changed.", "iLogic - Turn Work Features OFF")
Else
MessageBox.Show(myComponent & " now have visibility set to off.", "iLogic - Turn Work Features OFF")
End If

 

1 REPLY 1
Message 2 of 2
adam.nagy
in reply to: vince480

Hi,

 

Try to achieve exactly the same in the UI, that should give you an idea about what is going wrong.

 

Looking at your code I think what's missing is that you are working in the the definition of the subassembly (same as if opening it up directly) and so there as well you would need to change to "Default" design view before trying to change the Sketch visibility in the subassembly, and then also change to "Default" design view for the ComponentOccurrence of that subassembly, so the design view where the Sketch is invisible will be shown in the main assembly.

This might be of help to a certain extent: http://adndevblog.typepad.com/manufacturing/2013/07/occurrences-contexts-definitions-proxies.html

 

Cheers, 



Adam Nagy
Autodesk Platform Services

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

Post to forums  

Autodesk Design & Make Report