ilogic Rename solid skips second instance

ilogic Rename solid skips second instance

J-Camper
Advisor Advisor
540 Views
3 Replies
Message 1 of 4

ilogic Rename solid skips second instance

J-Camper
Advisor
Advisor

My colleague made a part that renames solids automatically.  The rule works great as long as you hard code any exceptions, but it renames any part outside of these exceptions.  I modified the rule to only rename parts created by a named feature, which are the only solids I want renamed.  It works kind of, it correctly renames the first solid, skips the second solid, and renames all other solids 1 increment short because of the missed solid.

 

Below is my code:

'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 prefix
prefix = "ST_"

'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

'write input back to custom iProperty
iProperties.Value("Custom", "Prefix") = prefix
i = 1

'rename all solid bodies incrementing suffix
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
	'look at all the features that make up the body
	For Each oFeature In solid.AffectedByFeatures
		'look at only "ST_ARRAY" feature
		If oFeature.Name = "ST_ARRAY"
			solid.Name = prefix + If(i < 10, "0" + CStr(i), CStr(i))
			i = i + 1
		End If
	Next
Next

'[ 
'UPDATE
InventorVb.DocumentUpdate()
'] UPDATE

 

 

0 Likes
Accepted solutions (1)
541 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@J-Camper,

 

Can you please provide Inventor file to test this behaviour? please make sure that files are non confidential.

 

It would be great if you provide screenshots of expected and actual results for solid body.

 

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 4

J-Camper
Advisor
Advisor
Accepted solution

I was actually able to fix it myself. 

 

When you change a rectangular pattern's quantity to 0 it suppresses the the feature and the first solid body remains in the list.  All I had to do was start my integer at 2 instead of 1.  Apparently it was skipping that first solid that never leaves the list, which is the first instance, and tried to rename the second instance the same as the first and didn't throw an error message "the name already exists", like renaming manually would.

0 Likes
Message 4 of 4

J-Camper
Advisor
Advisor

I need to clarify something about my above answer.  I was not aware that my colleague had set the rectangular pattern to suppress itself, in the browser tree, if the count was less than 3 [there are 2 pre-named solids that never change, so a 3 count means 1 new solid is created].  This was actually a cause for another issue, so we moved the suppression inside the rule, just before the renmaing section, and set the integer back to 1. All is well.

0 Likes