Hi All
I have an assembly which serves as a configurator. This Assy, needs to be copied many times. The assy contains 2 parts, which also must be copied. but when copied, the parts must have a new filename, and then the Rule cannot find them anymore. Therefore my plan is to define the filename with the configurator rule..
Example.:
Assy = Module.iam
Part1 = Module-1.ipt
Part2 = Module-2.ipt
I have this so far, but is doesn't work.. what do i put before the .ipt??..:
Filename = ThisDoc.FileName(False) 'without extension
[Filname-1 inserted here].ipt.Diameter = "30"
Solved! Go to Solution.
Solved by jdkriek. Go to Solution.
ThisDoc.FileName straight is only going to give you the name of the Assy - no good. What you need to do is loop through the occurrences in the Assy and plug them in. That way it doesn't matter what the file name is, the Assy will always find them.
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences Dim oName As String oName = oOcc.Name 'Debug Mode 'MsgBox(oName) 'Change a parameter in the parts Parameter(oName, "Diameter") = 30 Next
Hi Jonathan
Thanks for you reply, unfortunately my expertise in programming, can be stored in a very little box, so im not quite sure i understand what im suposed to do, can you explain it in more details, so i can understand it..?
Im with you as far as line 7. However, im not familiar with the AssemblyComponentDefinition and ComponentOccurrence... what they do... and what they do in this rule...
In this case there is only 1 occurrence of the two parts im renaming, if that makes any difference... 🙂
Hope you can make it simple enough for me to understand..
/LSA-Skan
Basically we are accessing the Assembly class then finding all Parts in the Assembly and grabbing their names automatically. So the program has the name of the parts regardless of what you decide to name them. At that point you can change parameters in those parts individually (not shown) or together if they share common parameters.
I'd also advise you to read the documentation. Simply search inside Programing Help.
Hi Jonathan
I have tried the rule, and found out that i left out an important thing..!!
The Assy i copy, have several other parts which i replace back and forth, but the 2 parts i mentioned are being altered directly from the assembly, and it is only these two i need my rule to recognize.
The descriptions you refer to under Programming help is only working for VBA, or am i wrong here? I would like to keep it in iLogic if possible, as my configurator rule now is at 1300 lines and counting..!
My lack of experience prevents me from converting the codes under programming help to iLogic 😞
(I am working on getting a course in VBA, to be able to figure this out for my self, but sadly, it won't be anytime soon)
Hi Again
After having worked alittle more with your example, i think i realized how the rule works... (removed the ' in your Debug line, helped me understand)
now i only need to get it working.. 🙂
The first part..:
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrencesDim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences Dim oName As String oName = oOcc.Name 'Debug Mode
'MsgBox(oName)
Next
Defines the Name of the item in Occurence, and i need to refer to that one when changing a parameter right?
If so, i could have a line further down my rule like so..:
Parameter (Module-1:1,"Diameter")= 30
But it doesn't work when i run the rule...
Am i misunderstanding the function of oName..? is oName just a name you made up, and therefore should be something like oModul-1, and then i add another string for oModule-2? either way i can't get it working... 😕
Hope you catch what i mean by all this.. 🙂
/LSA-Skan
iLogic is essentially VB.NET - which is more or less VBA - and all share the building blocks of Visual Basic. That's the only reason I linked you to the Programming Help section. There really isn't a help section for iLogic specifically that I'm aware of. Most VBA examples can be converted to iLogic in under a minute.
The example I gave you is formatted for iLogic already though. oOcc would be short for Occurrence - AKA your parts. So oOcc.Name will automatically contain the name of the parts as it loops through the Assembly. We've just assigned that to a variable called oName for convenience. The entire reason for oName is because you stated that the name of the part changes, so this method will allow you to change a parameter in those parts without knowing the name.
If I understand your last post correctly, you are saying that you only want to edit two parts out of many in an Assembly without knowing the names of either?
Thanks for the explanation, makes more sense to me now..!
When you say most VBA can be converted in under a minute, i would like to know how to covert it.. which expresions should be changed and into what..? where do you find this info..?
For the current case.: if i have 2 differet parts, with the same Parameter (Diameter), how will it know which part to alter? do i have to change the parameter name "Diameter" on one of the parts so theres never two of the same parameter name?
You understand me correct, but i do know the names of the parts i don't want to change, they are standard parts, Bearings and such... only 2 parts get new names and these are the only parts i change. the others just gets replaced.
Update on this..:
I have now tried applying your code into my rule. And even though i changed the Parameter names to RDiameter on one part, and ADiameter on the other, it still don't know the parts from eachother.. it asks for "ADiameter on Part 1 even thouhg that parameter only excists on Part 2. am i doing it wrong somehow..?
here is what i do...:
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
Dim oName As String
oName = oOcc.Name
Parameter (oName, "RDiameter") = 108 'Part1
Parameter (oName, "ADiameter") = 15 'Part2
Next
i found out that if i change all the oName lines to only refer to part 1, and then leave the Part 2 lines as they were, it now asks for a Part 1 Parameter on part 2.?!?
From what i can see, it does not know how to serparate the parameters for the two parts... am i back to square one on this..?
@LSA-skan wrote:... From what i can see, it does not know how to serparate the parameters for the two parts ...
Here you go, it will try to change the parameter if it exists. Otherwise it will continue.
Parameter.Quiet = True Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences Dim oName As String oName = oOcc.Name 'If RDiameter exists in occurrences Try Parameter (oName, "RDiameter") = 10 'Part1 Catch End Try 'If ADiameter exists in occurrences Try Parameter (oName, "ADiameter") = 15 'Part2 Catch End Try Next 'Update to change the parts RuleParametersOutput() InventorVb.DocumentUpdate()
Hi Jonathan
Sorry for the late response, i was on another project and had to pause this one. 😕
i have now tried to get your code integrated in mine, and it seems to be working, but im having some other issues now.
One of the parameters is being used in a formula in the specific part, to calculate a value to be used in the part. and it seems that this calculation does not work anymore..?!?!
All the parameters is being transfered correctly it seems, but this does not work now.:
Indv_diam = (RDiameter-RGods*2)
Indv_diam is the parameter im using to define a feature, and the 2 in the formula is the ones coming from the assy, where your code is running.
Do i need to make this formula in another way now, or what is wrong..?
/LSA
EDIT: i came to think that maybe i have to Dim the variables, and i tried String and Decimal with the result that my Inv_diam became 0. 😕
/LSA
Hi Jonathan
While trying to fabricate a simple model for you to illustrate my problem, i found that it works fine in this simple model. so it must be something from the rest of the code that intervenes.
I could post you the complete assy im working on, but you would have some work handed to you getting it working on your computer, as im refering to a lot of paths in my code, you will need to adjust it. Also much of the code is descibed in danish, so unless you can see through that it will be kinda messy... Also i would not be happy about posting it in this forum for everyone to download... 😕
I posted the simple model, so you can see what i was trying to show you...
Let me know if you have an idea of how to solve this.. 🙂
Hi Jonathan
I have now replaced all part requests in my entire code with your rule, but i have run into some special uses, where im not sure how to integrate your code..
Rulle-2.ipt is the part chaning name. When i use a variable from that part in an IF sentence, how do i convert that then..?
If Rulle-2.ipt.Noglevide >= AkselDia Then
Tried inserting the Parameter line in there, but won't let me...
About the ealier issue, where im having trouble with getting the formula in the part working, i found out that it only bugs when i change the size to a smaller version, if i keep making it bigger it works fine (Cylinder shape with hole. Hole bugs)... any ideas?
/LSA
Also this line doesn't work either...: how do i put this value in the iproperty value..?
For Each oOcc In oAsmCompDef.Occurrences oName = oOcc.Name Try iProperties.Value("Custom", "Raavare") = "Ø" & Diameter & "x" & Længde & "x" & Indbyg & "x" & Parameter (oName, "Alængde") & "-Ø" & AkselDia & "" & Aend1 & Aend2 Catch End Try Next
I think the problem is that iProperties.Value("Custom", "Raavare") as is only going to work in the Assembly.
And you are looking to change the iProperties in the sub parts as well - right?
Would be something like this:
iProperties.Value(oName, "Custom", "Raavare") = "Ø" & Diameter & "x" & Længde & "x" & Indbyg & "x" & Parameter (oName, "Alængde") & "-Ø" & AkselDia & Aend1 & Aend2
Actually im am trying to set iProperties in my assembly, but with an variable from my part. (length), but now that i think about it, my variable from the part is set from the assembly, so if i at each line where my Part variable is set, add a new Name variable with the same formula, and then use that in my iProperties..!
Like so..:
Parameter (oName, "Alængde") = Længde + 26
nLængde = Længde + 26
iProperties.value("Custom", "Raavare") = nLængde
Then i should avoid going to the part for the info. (Not sure why i did so in the first place.. )
By the Way I have Accepted your previous post as a solution on this matter... Thanks a bunch..!!
/LSA