I have a request for an iLogic code

I have a request for an iLogic code

chris
Advisor Advisor
1,094 Views
16 Replies
Message 1 of 17

I have a request for an iLogic code

chris
Advisor
Advisor

I'm looking to see if someone can whip up an iLogic code that will look at a single part or an assembly of parts and change the default "solid body" name from "solid1" to the part file name?

 

The reason I am asking is we use a 3rd party software in our workflow that upon import, of exported step files from Inventor, it looks at a "objects" solid body name to organize the parts, and as you can imagine, if you have an assembly with 500 parts, all with "solid1", it imports them as (1) object.

 

I reached out to the software developer to see if he can change the software on his end to reference file names vs. solid bodies, but that could take some time and while I don't mind simply copy and pasting the file name into the solid body name in Inventor for single files or sub part assemblies, it's gonna be a full time job on some of our larger assemblies which have hundreds of parts.

 

I'm not sure if this is possible or not, as far as iLogic having access to the solid body info, and while I can create iLogic rules for modeling and such, I have no idea how the iLogic Jedi's do anything outside of the drag and drop options.

 

I'm more than happy to buy pizza and have it delivered for anyone who can make this work

0 Likes
1,095 Views
16 Replies
Replies (16)
Message 2 of 17

Stakin
Collaborator
Collaborator

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim odef As PartComponentDefinition
odef = oDoc.ComponentDefinition
Dim oBod As SurfaceBody
For Each oBod In odef.SurfaceBodies
	If oBod.Name = "solid1" Then
		Exit For
	End If
Next
Dim opartName As String
opartName = oDoc.FullFileName
Dim ostart As Integer=InStrRev(oDoc.FullFileName, "\")+1
Dim oend As Integer=InStr(oDoc.FullFileName, ".ipt")
Dim oFileName As String 
oFileName=Mid(oDoc.FullFileName,ostart,oend-ostart)
MessageBox.Show(oFileName, "Title")
oBod.Name=oFileName

 

you must open your part with "solid1", and to try run this

0 Likes
Message 3 of 17

chris
Advisor
Advisor

@Stakin  Okay, that worked great!!!!  ( for single parts)... is there a way to have it run in an assembly and look for any solid body, even it it happens to be something other than "solid1"?

 

I got an error when trying to run it in an assembly

chris_2-1633504145098.png

 

 

 

 

 

0 Likes
Message 4 of 17

Stakin
Collaborator
Collaborator

@chris wrote:

@Stakin  Okay, that worked great!!!!  ( for single parts)... is there a way to have it run in an assembly and look for any solid body, even it it happens to be something other than "solid1"?

 

I got an error when trying to run it in an assembly

 

 

 

 

 

 


Try this, it can rename part and asm either,Include the subasm.

 

If you wanted rename other name's solid,

just change "solid1"  to your want.

 

 

 

Sub main
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	Dim oPrtDoc As PartDocument
	oPrtDoc=oDoc
	Dim oPrtdef As PartComponentDefinition
	oPrtdef = oPrtDoc.ComponentDefinition
	oChangePrtSolidName(oPrtdef)
ElseIf oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc=oDoc
	Dim oAsmdef As AssemblyComponentDefinition
	oAsmdef = oAsmDoc.ComponentDefinition
	oChangeAsmSolidName(oAsmdef)
End If	
End Sub

Private Function oChangeAsmSolidName(odef As AssemblyComponentDefinition)
Dim oDoc As AssemblyDocument
oDoc = odef.Document
Dim oCC As ComponentOccurrence
For Each oCC In odef.Occurrences
	If oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then		
		Dim oPrtDef As PartComponentDefinition
		oPrtDef = oCC.Definition
		oChangePrtSolidName(oPrtDef)
	ElseIf oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oSubAsmDef As AssemblyComponentDefinition
		oSubAsmDef=oCC.Definition
		Call oChangeAsmSolidName(oSubAsmDef)
	End If	
Next
End Function

Private Function oChangePrtSolidName(odef As PartComponentDefinition)
Dim oDoc As PartDocument
oDoc=odef.Document
Dim oBod As SurfaceBody
Dim opartName As String
opartName = oDoc.FullFileName
Dim oSolidName As string
oSolidName="solid1"
Try 
For Each oBod In odef.SurfaceBodies
	If oBod.Name = oSolidName Then
		Exit For
	End If
Next
Dim ostart As Integer=InStrRev(opartName, "\")+1
Dim oend As Integer=InStr(opartName, ".ipt")
Dim oFileName As String 
oFileName=Mid(opartName,ostart,oend-ostart)
'MessageBox.Show(oFileName, "Title")
oBod.Name = oFileName
Catch
MessageBox.Show("There is no solid Named " & oSolidName & " in the " & opartName, "Message")
end try
End Function

 

 

 

 

0 Likes
Message 5 of 17

Stakin
Collaborator
Collaborator
Sub main
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	Dim oPrtDoc As PartDocument
	oPrtDoc=oDoc
	Dim oPrtdef As PartComponentDefinition
	oPrtdef = oPrtDoc.ComponentDefinition
	oChangePrtSolidName(oPrtdef)
ElseIf oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc=oDoc
	Dim oAsmdef As AssemblyComponentDefinition
	oAsmdef = oAsmDoc.ComponentDefinition
	oChangeAsmSolidName(oAsmdef)
End If	
End Sub

Private Function oChangeAsmSolidName(odef As AssemblyComponentDefinition)
Dim oDoc As AssemblyDocument
oDoc = odef.Document
Dim oCC As ComponentOccurrence
For Each oCC In odef.Occurrences
	If oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then		
		Dim oPrtDef As PartComponentDefinition
		oPrtDef = oCC.Definition
		oChangePrtSolidName(oPrtDef)
	ElseIf oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oSubAsmDef As AssemblyComponentDefinition
		oSubAsmDef=oCC.Definition
		Call oChangeAsmSolidName(oSubAsmDef)
	End If	
Next
End Function

Private Function oChangePrtSolidName(odef As PartComponentDefinition)
Dim oDoc As PartDocument
oDoc=odef.Document
Dim oBod As SurfaceBody
Dim opartName As String
opartName = oDoc.FullFileName
Dim oSolidName As string
oSolidName="solid1"
Dim oHasSolid1OrNot As Boolean=False
  
For Each oBod In odef.SurfaceBodies
	If oBod.Name = oSolidName Then
           oHasSolid1OrNot=True
		Exit For
	End If
Next
if oHasSolid1OrNot then
Dim ostart As Integer=InStrRev(opartName, "\")+1
Dim oend As Integer=InStr(opartName, ".ipt")
Dim oFileName As String 
oFileName=Mid(opartName,ostart,oend-ostart)
'MessageBox.Show(oFileName, "Title")
oBod.Name = oFileName
else
MessageBox.Show("There is no solid Named " & oSolidName & " in the " & opartName, "Message")
end if
End Function

pls try this version,modify some thing

 

0 Likes
Message 6 of 17

chris
Advisor
Advisor

@Stakin That worked... I took out the message box, as it was coming up after all the solids were changed, but was forcing me to accept each message. Also I had to capitalize "Solid1", as it didn't work the first time because it was looking for "solid1"... where and when do you want the pizza!

0 Likes
Message 7 of 17

chris
Advisor
Advisor

@Stakin  THANK YOU!!

0 Likes
Message 8 of 17

chris
Advisor
Advisor

@Stakin  I just tried it on one of my assemblies and sent the step to the 3rd party software, it still came back with a few merged meshes as those parts had multiple solid bodies. Obviously I can't change the iLogic code to simply look for another solid name, because it would over-write the part number in the solid one... is there a way to add to the iLogic code so that enter in 5 solid body options and if it found multiples it would name the first one the "file name" and all the others would get named "file name__2"   "filename__3"   "File name__4"   "filename__5"

 

if you can make that work I'll be paying you! 

0 Likes
Message 9 of 17

Stakin
Collaborator
Collaborator

 

Sub main
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	Dim oPrtDoc As PartDocument
	oPrtDoc=oDoc
	Dim oPrtdef As PartComponentDefinition
	oPrtdef = oPrtDoc.ComponentDefinition
	oChangePrtSolidName(oPrtdef)
ElseIf oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc=oDoc
	Dim oAsmdef As AssemblyComponentDefinition
	oAsmdef = oAsmDoc.ComponentDefinition
	oChangeAsmSolidName(oAsmdef)
End If	
End Sub

Private Function oChangeAsmSolidName(odef As AssemblyComponentDefinition)
Dim oDoc As AssemblyDocument
oDoc = odef.Document
Dim oCC As ComponentOccurrence
For Each oCC In odef.Occurrences
	If oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then		
		Dim oPrtDef As PartComponentDefinition
		oPrtDef = oCC.Definition
		oChangePrtSolidName(oPrtDef)
	ElseIf oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oSubAsmDef As AssemblyComponentDefinition
		oSubAsmDef=oCC.Definition
		Call oChangeAsmSolidName(oSubAsmDef)
	End If	
Next
End Function

Private Function oChangePrtSolidName(odef As PartComponentDefinition)
Dim oDoc As PartDocument
oDoc=odef.Document
Dim oBod As SurfaceBody
Dim opartName As String
opartName = oDoc.FullFileName
Dim oSolidQty As Integer=0
  
For Each oBod In odef.SurfaceBodies
oSolidQty=oSolidQty+1

Dim ostart As Integer=InStrRev(opartName, "\")+1
Dim oend As Integer=InStr(opartName, ".ipt")
Dim oFileName As String 
oFileName=Mid(opartName,ostart,oend-ostart)
if odef.SurfaceBodies.Count>1 then
oBod.Name = oFileName & "_" & oSolidQty
else
oBod.Name = oFileName
end if
Next
End Function

 

And this time is another pizza?^-^

Below code will change All the bodies name to Filename_1\2\3;No matter  what the solid original  name is.

0 Likes
Message 10 of 17

Stakin
Collaborator
Collaborator
Sub main
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
	Dim oPrtDoc As PartDocument
	oPrtDoc=oDoc
	Dim oPrtdef As PartComponentDefinition
	oPrtdef = oPrtDoc.ComponentDefinition
	oChangePrtSolidName(oPrtdef)
ElseIf oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oAsmDoc As AssemblyDocument
	oAsmDoc=oDoc
	Dim oAsmdef As AssemblyComponentDefinition
	oAsmdef = oAsmDoc.ComponentDefinition
	oChangeAsmSolidName(oAsmdef)
End If	
End Sub

Private Function oChangeAsmSolidName(odef As AssemblyComponentDefinition)
Dim oDoc As AssemblyDocument
oDoc = odef.Document
Dim oCC As ComponentOccurrence
For Each oCC In odef.Occurrences
	If oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then		
		Dim oPrtDef As PartComponentDefinition
		oPrtDef = oCC.Definition
		oChangePrtSolidName(oPrtDef)
	ElseIf oCC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oSubAsmDef As AssemblyComponentDefinition
		oSubAsmDef=oCC.Definition
		Call oChangeAsmSolidName(oSubAsmDef)
	End If	
Next
End Function

Private Function oChangePrtSolidName(odef As PartComponentDefinition)
Dim oDoc As PartDocument
oDoc=odef.Document
Dim oBod As SurfaceBody
Dim opartName As String
opartName = oDoc.FullFileName
Dim oSolidQty As Integer=0  
For Each oBod In odef.SurfaceBodies
oSolidQty=oSolidQty+1
Dim ostart As Integer=InStrRev(opartName, "\")+1
Dim oend As Integer=InStr(opartName, ".ipt")
Dim oFileName As String 
oFileName=Mid(opartName,ostart,oend-ostart)
if odef.SurfaceBodies.Count>1  and oSolidQty <> 1 then
oBod.Name = oFileName & "__" & oSolidQty
else
oBod.Name = oFileName
end if
Next
End Function

Hope this version can meet all your want.

0 Likes
Message 11 of 17

chris
Advisor
Advisor

@Stakin Let me get back to the office to test this... how on earth do you know how to write all that stuff? You should make some tutorials... I'd buy them!

 

0 Likes
Message 12 of 17

chris
Advisor
Advisor

@Stakin    FLAWLESS VICTORY!!!!!

 

Do you have PayPal, I need to send you $100!

Just email me:  chris@trinitydesignandfabrication.com

 

0 Likes
Message 13 of 17

Stakin
Collaborator
Collaborator

Where is pizza?^_^

0 Likes
Message 14 of 17

chris
Advisor
Advisor

Where are you located? and what's the name of the place you want a pizza from? What kind of pizza and when do you want it delivered?

I still want to send you some money! Good work deserves to be rewarded!

0 Likes
Message 15 of 17

Stakin
Collaborator
Collaborator

I am in china,I believe we are thousands of miles apart, oceans and mountains separated;where are you?

Are you sure the pizza won't go bad when it's delivered?

 

Maybe the program can do more for you,

such as:

1、generate the list of solid body....

2、Convert the model to the common format

3、auto generate the part and assembly depend on the data sheet

.....

 

 

0 Likes
Message 16 of 17

chris
Advisor
Advisor

The only other thing I can think to add to the toll would be to have it run through each part and change the units to inches and angle to degree... we seem to get a lot of parts/assemblies that are in meters/mm/cm and radians

I'm serious about wanting to send you some money

 

0 Likes
Message 17 of 17

Stakin
Collaborator
Collaborator

I add some Logic for the part in the assembly  to avoid repeated modifications,and add the unit change to you want.

I sent it to you mail,check it please

 

 

0 Likes