×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks 2009 - Link Part/Subassembly Custom Property to Assy Qty
2

SolidWorks 2009 - Link Part/Subassembly Custom Property to Assy Qty

SolidWorks 2009 - Link Part/Subassembly Custom Property to Assy Qty

2
(OP)
From the SolidWorks Forums:

1. Create a non-configuration-specific custom property in the main assembly called "Cfg4Qty". In that property put the name (case-sensitive) of the configuration of the main assembly that you want to use to drive the quantity.
2. Create two non-configuration-specific custom properties, one called "code" and the other called "code2". They should be text type properties. Just for now, put the numbers "1" and "2" into them.
3. Create the equation:

"Dummy" = "code""code2"

If you've done this right so far, the value of "Dummy" should be 12.

4. Go back to the custom properties. Click in the box for the "code" custom property such that it highlights the "1" that's in there.
5. Paste the following code into that property:

1
Dim myAsy As AssemblyDoc
Dim myCmps
Dim Cfg As String
Dim CmpDoc As ModelDoc2
Dim i As Long
Dim j As Long
Dim cCnt As Long
Dim NoUp As Long
Dim myCmp As Component2
Dim tCmp As Component2
dim tm as double
tm = timer
Set myAsy = Assembly
If Assembly.ConfigurationManager.ActiveConfiguration.Name <> Assembly.CustomInfo2("", "Cfg4Qty") Then
Assembly.Extension.ShowSmartMessage "Qtys not updated due to config", 1000, True, True
Exit Sub
End If
NoUp = 0
myCmps = myAsy.GetComponents(False)
For i = 0 To UBound(myCmps)
Set myCmp = myCmps(i)
If (myCmp.GetSuppression = 3) Or (myCmp.Get

Make sure you don't copy any blank lines before or after this code.

6. Do the same thing for the "code2" property,using the following code:

Suppression = 2) Then
cCnt = 0
Set CmpDoc = myCmp.GetModelDoc
Cfg = myCmp.ReferencedConfiguration
For j = 0 To UBound(myCmps)
Set tCmp = myCmps(j)
If tCmp.GetSuppression <> 0 Then
If tCmp.GetModelDoc2 Is CmpDoc Then
If tCmp.ReferencedConfiguration = Cfg Then
cCnt = cCnt + 1
End If
End If
End If
Next j
CmpDoc.AddCustomInfo3 Cfg, "AutoQty", 30, ""
CmpDoc.AddCustomInfo3 Cfg, "QtyIn", 30, ""
CmpDoc.CustomInfo2(Cfg, "AutoQty") = cCnt
CmpDoc.CustomInfo2(Cfg, "QtyIn") = Assembly.GetTitle & " Cfg " & Assembly.ConfigurationManager.ActiveConfiguration.Name
Else
NoUp = NoUp + 1
End If
Next i
Assembly.Extension.ShowSmartMessage NoUp & " Parts not updated due to lightweight (" & timer - tm & "s)", 10000, True, True

This will create two config-specific custom properties in every component part file/configuration referenced in the main assembly. The one called "AutoQty" will contain the counted number of parts. The one called "QtyIn" will contain the name of the main assembly and the configuration they are counted in. The AutoQty property will be updated every time the configuration specified in "Cfg4Qty" is rebuilt.

Attached is a sample assembly that uses this method. Whenever the "Default" configuration of the assembly is rebuilt, the AutoQty and QtyIn properties of the parts are updated. If you change the Cfg4Qty custom property of the assembly to "ConfigWithExtraParts" then the parts will be updated with the quantities from that configuration. I've included a drawing with a BOM just for reference to show how the properties update.

Of course, the automatic updating adds time to the rebuild, and it gets more noticeable with large assemblies. You can easily disable the code by un-checking the "active" box for the "Dummy" = "code""code2" equation.
 

-handleman, CSWP (The new, easy test)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources