Assembly controlled properties
Assembly controlled properties
(OP)
I've seen Handleman's post on controlling properties of parts based on the parent assembly, and it seems like it could help me with something I've been trying to accomplish for a while now. I don't get exactly how it works, and the new API help file just confuses me. My goal is (seems) pretty simple, so let's see what you guys can come up with...
I have a few assemblies, assy1.sldasm, assy2.sldasm, etc. In each assembly there will be a part called insulation.sldprt.
I would like to put a value into each assembly that will then add that value to a given custom property in insulation.sldprt. That way, insulation.sldprt will never need to be updated itself, just the value in the assembly depending on how much insulation it uses.
To help you understand my goal, we have a utility that imports BOM information from an open assembly directly into our ERP. So when an assembly is opened and imported, the assembly drives the property of insulation.sldprt, which would eliminate the need for multiple configurations.
I hope you can understand what I'm trying to say here, and any and all input will be greatly appreciated.
Thanks,
Matt
I have a few assemblies, assy1.sldasm, assy2.sldasm, etc. In each assembly there will be a part called insulation.sldprt.
I would like to put a value into each assembly that will then add that value to a given custom property in insulation.sldprt. That way, insulation.sldprt will never need to be updated itself, just the value in the assembly depending on how much insulation it uses.
To help you understand my goal, we have a utility that imports BOM information from an open assembly directly into our ERP. So when an assembly is opened and imported, the assembly drives the property of insulation.sldprt, which would eliminate the need for multiple configurations.
I hope you can understand what I'm trying to say here, and any and all input will be greatly appreciated.
Thanks,
Matt






RE: Assembly controlled properties
-handleman, CSWP (The new, easy test)
RE: Assembly controlled properties
I was thinking there could be a custom property in the assembly called InsQty or something. This would be changed by the engineer, and when the assembly is rebuilt, it reads that value, and adds it to a config specific property called M2MQty in insulation.sldprt.
That way the insulation quantity is saved per assembly, and insulation.sldprt is just there to for importing the BOM.
RE: Assembly controlled properties
RE: Assembly controlled properties
The code as posted goes through every single document and adds quantity. All you need to do is make it check the file path to see if it contains "insulation.sldprt". If it does, you get the custom property value from the assembly and add it to the part. If not, ignore it.
-handleman, CSWP (The new, easy test)
RE: Assembly controlled properties
Eric
RE: Assembly controlled properties
Another option might be to have an equation at the assembly level drive a parameter at the part level.
RE: Assembly controlled properties
I've tried a bunch of different code. The main problem is that when the code doesn't work, it just shows "???" for the equation, so I don't know what exactly is causing the problem. What is the purpose of breaking the code up into two different properties? Why wouldn't it work if you just put it into one?
EEnd,
Initially, I tried using virtual components, but had a few different reasons as to why that would not work. The way I see this working, there will actually only be one file that is used in every assembly. The part file only changes temporarily when it is opened, and is never actually saved (PDM). All the info is stored in the assemblies, and is passed down to the part file when they are opened/rebuilt.
TheTick,
I want to stay away from DTs if at all possible. I want this to be as automatic as possible. Your second option is basically what I'm trying to accomplish based on handleman's code.
RE: Assembly controlled properties
The code should work the same for the most part whether it's run from the VBA editor or from the equation. The main difference is that with the equation you automatically get the ModelDoc2 object for the document owning the equation as the variable called "Part", and the SldWorks.SldWorks object as the variable called "swApp". Just paste the code into a new macro and add declarations/initialization code for "Part" and "swApp" and you should be able to run/debug from VBA window.
Incidentally, the automatic "Part" variable is key for making the code work as intended in the equation - you can't use ActiveDoc in the equation, because the equation could be evaluated while some other document is the active document. The only way for the code to know which document "owns" it is by this automatic "Part" variable.
-handleman, CSWP (The new, easy test)
RE: Assembly controlled properties
1
Dim myAsy As AssemblyDoc
Dim myCmps
Dim CmpDoc As ModelDoc2
Dim i As Long
Dim InsQty As Long
Dim myCmp As Component2
Set myAsy = Assembly
InsQty = myAsy.CustomInfo("InsQty")
myCmps = myAsy.GetComponents(True)
For i = 0 To UBound(myCmps)
Set myCmp = myCmps(i)
If instr(myCmp.GetPathName, "Insulation.SLDPRT") Then
Set CmpDoc = myCmp.GetModelDoc
CmpDoc.DeleteCustomInfo2 "Default", "M2MQty"
CmpDoc.AddCustomInfo3 "Default", "M2MQty", 30, InsQty
End If
next i
So once the appropriate data is in the assembly, all I have to do is change the property "InsQty" and the part file will be updated upon rebuild.
Thanks for the help