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: 

Select and Turn off UCS Triads with ilogic or VBA

11 REPLIES 11
Reply
Message 1 of 12
ciprian.tripon
586 Views, 11 Replies

Select and Turn off UCS Triads with ilogic or VBA

Hello,

is that possible? And I mean not over general Inventor options or visibility.

 

Thank you.

11 REPLIES 11
Message 2 of 12
WCrihfield
in reply to: ciprian.tripon

Hi @ciprian.tripon.  Yes.  It is possible.  Their visibility can be controlled either individually, or as a whole, through multiple possible processes.  Below is a very simple example of finding all UCSs that were created directly within an assembly, then turning their visibility off.  Is this what you were looking for?

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oUCSs As UserCoordinateSystems = oADef.UserCoordinateSystems
If oUCSs.Count = 0 Then Exit Sub
For Each oUCS As UserCoordinateSystem In oUCSs
	If oUCS.Visible Then oUCS.Visible = False
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 12
WCrihfield
in reply to: ciprian.tripon

An alternate route of turning off visibility of specifically just the 'Triad', would be like the following example, but I believe that will effect the whole document, not just one UCS.

Dim oADoc As AssemblyDocument = ThisDoc.Document
oADoc.ModelingSettings.UserCoordinateSystemSettings.ShowTriad = False

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 12
ciprian.tripon
in reply to: WCrihfield

Thank you. It is one step forward. I need to search in all subassemblies and parts. How do I search in the tree?
thank you
Message 5 of 12
WCrihfield
in reply to: ciprian.tripon

Hi @ciprian.tripon.  Here is an example iLogic rule you can try out, which will loop through every referenced document of the entire assembly, and attempt to turn off visibility of all UCSs.  I have the one line in the second loop pretty condensed, but it can be normalized/structured onto multiple lines, if its hard to follow.  I also included the secondary method in there, but left that line commended out for now.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
For Each oRefDoc As Document In oAllRefDocs
	If oRefDoc.IsModifiable = False Then Continue For
	Dim oUCSs As UserCoordinateSystems = oRefDoc.ComponentDefinition.UserCoordinateSystems
	If oUCSs.Count = 0 Then Continue For
	For Each oUCS As UserCoordinateSystem In oUCSs
		If oUCS.Visible Then : Try : oUCS.Visible = False : Catch : End Try : End If
	Next
	'Try : oRefDoc.ModelingSettings.UserCoordinateSystemSettings.ShowTriad = False : Catch : End Try
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 12
ciprian.tripon
in reply to: WCrihfield

Thank you for your answer. Unfortunately it doesn't work. Can you explain this line? "If oUCS.Visible Then : Try : oUCS.Visible = False : Catch : End Try : End If"
Thank you.
Message 7 of 12
WCrihfield
in reply to: ciprian.tripon

Sure.  That line is super condensed.  The code in that one line could have taken up 6 lines, if laid out naturally,  but since most of those lines would have only contained 1 or 2 words, I used the colon symbol (:), which acts like a line break, to condense them all into one row.

If oUCS.Visible Then
	Try
		oUCS.Visible = False
	Catch
	End Try
End If

The first line could have also included "= True" in there between 'Visible' and 'Then', but that is not really necessary when checking the value of a Boolean in this way, so I left it out to further condense the line of code.

The other line of code below that, which I left commented out, was done that way also.  It is condensing 4 lines of code into one line, because each of the other 3 lines only contain one keyword.  However, if you want to see feedback when one of those lines of code fails, then laying these lines out naturally would be necessary, because you would want to put some code within the 'Catch' side of the Try...Catch...End Try blocks of code, so that that code will run when the 'Try' portion fails.

Below is the same code, but not condensed, and with some iLogic Logger feedback when one of those settings encounters an error.  The believe the iLogic Logger became available in 2019 version of Inventor, so if you have an earlier version of Inventor, you may need to change those to something like a MsgBox() or MessageBox.Show().

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oAllRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
For Each oRefDoc As Document In oAllRefDocs
	If oRefDoc.IsModifiable = False Then Continue For
	Dim oUCSs As UserCoordinateSystems = oRefDoc.ComponentDefinition.UserCoordinateSystems
	If oUCSs.Count = 0 Then Continue For
	For Each oUCS As UserCoordinateSystem In oUCSs
		If oUCS.Visible Then
			Try
				oUCS.Visible = False
			Catch
				Logger.Error("Error setting oUSC.Visible = False" & vbCrLf & _
				"oUCS.Name = " & oUCS.Name & vbCrLf & _
				"oRefDoc.FullDocumentName = " & oRefDoc.FullDocumentName)
			End Try
		End If
	Next
	Try
		oRefDoc.ModelingSettings.UserCoordinateSystemSettings.ShowTriad = False
	Catch
		Logger.Error("Error setting 'ShowTriad = False'" & vbCrLf & _
		"oRefDoc.FullDocumentName = " & oRefDoc.FullDocumentName)
	End Try
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)

Did the code throw an error when you ran it?  If so, what did the error message say (in detail)?  If it did not throw an error, then did it make some changes, but just not all the needed changes, or did it not seem to make any changes at all?  What year/version of Inventor are you using?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 12
ciprian.tripon
in reply to: WCrihfield

Sorry for the late response. It does not seem to make any changes at all.
I am running Inventor 2022 Build: 492, Release 2022.4.1.
Message 9 of 12
WCrihfield
in reply to: ciprian.tripon

Hi @ciprian.tripon.  You are using the same version as me right now, so maybe the failure has something to do with ModelStates and not having a reference to the factory version of the document, but I am not sure.  I changed a few things within the code to help ensure that it will be working with the factory version of each document, if a factory exists.  I also expanded a few other areas of the code to provide a lot more feedback when things happen, using the iLogic Logger for expediency.  Then after you run the rule, you can look at the iLogic Log tab and see what all happened.  That may provide some clues as to what may need to change to make this work better for you.  Normally, you would have set all the object visibility stuff up the way you wanted them within each individual document as you created them, than saved those settings within one or more DVR's (DesignViewRepresentations), because that is what those are for.  Then when you add that model to an assembly as a component, you set that assembly component's DVR to the one you created within its referenced file, so it will appear exactly the way you want it.  Trying to control visibility related settings in a top to bottom fashion within an assembly can be pretty complicated, because that is not the natural order that was intended.  If each file had a specific DVR in it, where everything was set the way you wanted it, then you could just ensure that each assembly component was set to that DVR, and make it 'Associative'.  When you change visibility settings by code, without any thought of DVR's, you break any 'Associative' settings you may have had in place, then when visibility/color related changes happen in the referenced file, those changes may not be immediately reflected in the parent assembly. 

Attached is the text file of the code I revised.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12
ciprian.tripon
in reply to: WCrihfield

Thank you. These are some old jobs that need updating. Now I am working with DVR.
Back to the ilogic. It does turn off the UCS visibility in the subassemblies and parts, but in the top assembly they are still visible. I think that I need to catch and change the ViewRep from Master in every subassembly.
Message 11 of 12
rajdude2
in reply to: ciprian.tripon

Hello,

Can this be run on a whole library full of parts (.ipt files)?


I have the same issue and seems like this may be a solution and I have another thread here for my problem:

https://forums.autodesk.com/t5/inventor-forum/ucs-arrows-suddenly-visible-for-many-not-all-parts-in-...


There is one major problem, I do not know what is iLogic and more importantly how to use it?

I did look at the documentation.


Seems like iLogic will create copies of all our parts with UCS turned off. Is that so?

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-1645DF9F-1DB5-4E61-ABE7-888B32DBF254


I do not want duplicates in the library.

Message 12 of 12
WCrihfield
in reply to: rajdude2

Hi @rajdude2.  For us to teach you all about iLogic by typing out responses to a forum post is a very tall order.  Maybe the best place to start would be looking at the online help documentation on that subject at the following link, and within all of the links at that web site.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-AB9EE660-299E-408F-BBE1-AFE44C723F59 

If that link does not work, you can get there by clicking on the '?' symbol (help button) near the upper right corner of your Inventor application.  Then within the web page it brings up, follow these topics:  "iLogic", then "iLogic" again.

Especially the following:

To Work with Rules in iLogic 

You would first need to make sure that the iLogic DockableWindow is visible within Inventor.  To do that, go to your View tab, then click on the 'User Interface' tool, then make sure the checkbox named "iLogic" is checked.  Once you see the iLogic tab shown next to your Model browser tree, click on that.  Then click on the 'Rules' sub heading.  That open area below that is where you can store iLogic rules that will be saved within that specific document.  To create one, just right click your mouse in that area, and select 'Add Rule'.  It will prompt you to provide a name for the rule, then it will open the iLogic Rule Editor dialog.  Then you can copy code from this forum, and paste it into that window, then click on the Save button near the lower right corner of that window.  If you clicked Save & Run button it would save the code changes, then run the rule.  However, once you have just saved the rule, you can close that dialog, then right click on the name of the rule you just created, and choose Run Rule to run that rule also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report