Hi Everyone
This is my first post and I have a tricky request.
Can someone help to achieve the renaming of solid bodies by array list - click on the solid body and rename by a pre-defined name list (dropdownlist) from excel or text document?
This is a mix from the post:
http://inventortrenches.blogspot.ae/2012/02/ilogic-to-rename-all-solid-bodies.html
and
http://inventortrenches.blogspot.ae/2013/07/ilogic-add-standard-virtual-parts-from.html
and
http://inventortrenches.blogspot.ae/2013/01/ilogic-solid-body-visibility.html
The main idea is to always assure same part names when making components for example for furniture like TOP PANEL or RIGHT PANEL and this in an easy way to avoid writing always over and over again same naming.
Your input and ideas are well appreciated.
Thanks
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Here is an iLogic solution.
To be ran from the part file.
Add extra names by just adding more lines of oList.Add, following the current format.
It runs in a loop until you hit escape during selection or use the exit button during list box.
Sub Main() Dim oList As New List(Of String) oList.Add("Top") oList.Add("Right Panel") Do oBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick Body to Rename") If oBody Is Nothing GoTo ExitSelectLoop End If oName = InputListBox("Select the name for this body", oList)
If oName <> "" Then oBody.Name = oName
Else
GoTo ExitSelectLoop
End if Loop ExitSelectLoop: End Sub
.... you guys rock!
I tested it and is exactly what I am looking for - awesome and well done.
Wich I would have the knowledge you guys have - but working on it.
Thanks for your support!
Not sure if this is the best place to post this follow-on request, but seems to be the latest thread referencing this rule:
http://inventortrenches.blogspot.ae/2012/02/ilogic-to-rename-all-solid-bodies.html
I have been trying to add a simple If /Then condition to this rule so that it will only rename bodies in a multi-body part that are marked for export (or, alternatively, only bodies that are visible). Often I have bodies in a multi-body part that will not make the cut to be a part in the assembly for which I am making components, and therefore I would like the rule to skip these bodies when numbering in sequence so the resulting assembly does not have gaps in part numbers. I have also tried to make the skipping behavior contingent on body visibility, but always get an error with my code (which I’m sure is just totally incorrect). Any thoughts? Seems like this should be an easy one for you guys.
Thanks in advance for any help.
@Anonymous You probably would have been better making a new thread.
However, based on the code in your supplied link
and using the API help to figure out the available calls:
(found here: http://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=GUID-F20C9F1B-2BB1-4B7E-BA3E-FF1731F9F0DA)
The modified code should look something like this:
'check for custom iProperty and add it if not found Dim prefix As String = "Prefix" customPropertySet = ThisDoc.Document.PropertySets.Item _ ("Inventor User Defined Properties") Try prop= customPropertySet.Item(prefix) Catch ' Assume error means not found customPropertySet.Add("", prefix) End Try 'write the part number to the Prefix iProperty if it is empty if iProperties.Value("Custom", "Prefix") = "" Then iProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_" else end if 'check that this active document is a part file Dim partDoc As PartDocument If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then MessageBox.Show ("Please open a part document", "iLogic") End If 'define the active document partDoc = ThisApplication.ActiveDocument Dim solid As SurfaceBody Dim i As Integer 'get input from user prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix")) 'write input back to custom iProperty iProperties.Value("Custom", "Prefix") = prefix i = 1 'renam
e all solid bodies incrementing suffix For Each solid In partDoc.ComponentDefinition.SurfaceBodies
If solid.Exported = True solid.Name = prefix + IIf(i < 10, "0" + CStr(i), CStr(i))
end if
i = i + 1 Next
Thanks MechMachineMan!
Looks like I had the "end if" in the wrong place.
Only thing is, that code still numbers the parts based on the sequence in the browser, i.e. if the first body in my browser is a reference body (not marked for export) then the first part in exported assembly will be Prefix-02. Maybe it's too complicated, but is there a way to have the rule only change the names of bodies to be exported and number only those bodies in sequence?
I suppose this was a problem (at least from my use perspective) with the original code as well.
Thanks again for the reply.
Hi All,
The supplied code works great, however as was previously mentioned is there a way
to only rename visible solids in this manner?
Or alternately is there a way to rename only selected solids
potentially using pick?
Let me know what you think
Regards
Bruce
@Anonymous
Yes. Move the
i = i + 1
line inside of the If statement that controls the processing criteria.
ie; move it up 2 lines above the "End If".
Sure. Use the appropriate call available on the solid object with an appropriate "If" statement to cause the rule to process as you require. (Much the like If solid.Exported = True, except more like "If solid.Visible = true")
Alternatively, you can search around more on the forums to find code that would process a "select set" (which is better than pick functionality in this case) and figure out how to modify the code to use that as a criteria instead of the "if" statements.
Can't find what you're looking for? Ask the community or share your knowledge.