I logic to replace the part number

I logic to replace the part number

Anonymous
Not applicable
822 Views
4 Replies
Message 1 of 5

I logic to replace the part number

Anonymous
Not applicable

Hello Forum

 

Need help !!!

Can anyone please provide code for " REPLACING THE PART NUMBER " used in I logic,

Since each part is unique number , If I am copying the assembly want to change the parameters

but I logic is built for previous part reference number .. I don't want to go and edit each time in ilogic

 

my plan to create new user parameters enter the new drawing number,,

i logic code should replace the existing old part number

 

Example : Find and replace

Parameter("6097-100", "d0") = PIPE_PRJ_TOP
Parameter("60975-100", "d1") = -Sqrt ((PIPE_X * PIPE_X)+ (PIPE_Y*PIPE_Y))
Parameter("60975-100", "d2") = ((PIPE_Z+PIPE_PRJ_TOP)+2.5)

my required code.. to replace "6097-100" / "6097" with new number.. which will be entered in user parameters at top assembly...

 

Thanks

Vijay

0 Likes
823 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor

Maybe this ? From top level assembly :

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim oAssCompDef As AssemblyComponentDefinition
oAssCompDef = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence

For Each oOcc In oAssCompDef.Occurrences
	
	Try 
		
		oOcc.Definition.Parameters.UserParameters.Item("PartParameterName1").Value = oAssCompDef.Parameters.UserParameters.Item("TopAssyParameterName1").Value
		oOcc.Definition.Parameters.UserParameters.Item("PartParameterName2").Value = oAssCompDef.Parameters.UserParameters.Item("TopAssyParameterName2").Value
	        oOcc.Definition.Parameters.UserParameters.Item("PartParameterName3").Value = oAssCompDef.Parameters.UserParameters.Item("TopAssyParameterName3").Value

Catch End Try Next

Replace parameters name as needed. 🙂

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 5

J-Camper
Advisor
Advisor

@Anonymous,

 

If I understand correctly, you have an assembly with iLogic rule to drive parameters in component parts/assemblies.  Then you want to be able to copy design that assembly with new component parts/assemblies and have the iLogic work without changing it.

 

If that is correct, you should stabilize your browser node names.  For example:

Parameter("6097-100", "d0") = PIPE_PRJ_TOP

You would want to rename the browser node for "6097-100" to be more generic, and not have them rename to part number.  I don't know what this part is, but lets just say it is a pipe Flange.  You rename the browser node to "Flange" and then use this line in your iLogic code:

Parameter("Flange", "d0") = PIPE_PRJ_TOP

With the name stabilized, you can copy design the main assembly as many times as you need and the new part number for the "Flange" component, whatever it is, won't matter.  The re-named browser node would remain the same and your iLogic would not have to change.

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hi, 

 

Thank you so much for the code and help..

as you more generic name " flange" , could be given in top assembly while copying it for next design all defined parameters will work.. in my case.. each part name is linked to external drawing generator number while its linked to ERP system,, unless it wont save in that format .. ERP wont recognise the part.. 

if some one copying my model.. they can't trace and change the genric number to ERP number its trick is int.

 

let me keep it simple words..

 

step 1... create user parameter which is unique number generated by ERP .. for eg.. 01012021

             same number entered in main assembly , as part number user defined as STRING = 01012021

step2 ;  below parameter "7560975-100" is old part , should replace with new number mentioned above

nothing but find and replace..

Parameter("7560975-100", "d0") = PIPE_PRJ_TOP

the reason behind is I have many parts with featured derived assly and part..

can't keep it maually , //

 

hope its clear.. can  I get VBA code

looking forward for soln.

 

Regards

Vijay

 

0 Likes
Message 5 of 5

J-Camper
Advisor
Advisor

Automating a find and replace of iLogic code is probably not the best practice, I'm sure it can be done, but I have another option that might work for your situation.

 

When part number user defined as STRING = 01012021 is created in your main assembly as a User Parameter, you can use that user parameter for the component name.  Example:

 

Main assembly has a text User Parameter "ERP_Name1", which is changed to the new ERP name when you copy design the assembly, but still refers to the "Flange" Part I hypothesized earlier.  Then you can make the parameter calls using this User parameter, either directly or through a String variable:

Parameter(ERP_Name1, "d0") = PIPE_PRJ_TOP

'Or

Dim DynamicPartName1 As String = Parameter("ERP_Name1") 
Parameter(DynamicPartName1, "d0") = PIPE_PRJ_TOP

This should allow your component names to reflect the ERP name and still "Stabilize" the iLogic code.  You would need a User Parameter for each component, but that should probably be fine since you would only have to set them up once.

 

Let me know how this workflow feels in your situation.

0 Likes