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

Modify Part Script to Work At Assembly

Modify Part Script to Work At Assembly

Modify Part Script to Work At Assembly

Can somebody please help me modify this code which adds 3 new Parameters to a part to work at the assembly level and adds these parameters to every part and product?

CODE --> CATScript


Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim product1 As CATBaseDispatch
Set product1 = partDocument1.GetItem("")

Dim parameters1 As Parameters
Set parameters1 = product1.UserRefProperties

Dim strParam1 As StrParam
Set strParam1 = parameters1.CreateString("DETAIL NUMBER", "")

strParam1.ValuateFromString ""

Dim parameters2 As Parameters
Set parameters2 = product1.UserRefProperties

Dim strParam2 As StrParam
Set strParam2 = parameters2.CreateString("MATERIAL", "")

strParam2.ValuateFromString ""

Dim parameters3 As Parameters
Set parameters3 = product1.UserRefProperties

Dim strParam3 As StrParam
Set strParam3 = parameters3.CreateString("STOCK SIZE", "")

strParam3.ValuateFromString ""

End Sub 

RE: Modify Part Script to Work At Assembly

you just need too use multiple selection, for those parts from assembly and then run for loop to set these parameters.
You need to define "partDocument1" using selection.


RE: Modify Part Script to Work At Assembly

Instead of using a partdocument object, use the activedocument object. Activedocument can contain parts, drawings, or assemblies. Not all functions behave the same on all types of objects though.

You are also will want to run through a loop to assign the parameters to each subassy and subproduct while walking down your assembly structure step by step. You will need to use the appropriate "collectors" to do that.


Search for the objects using a criteria and then assign your parameters to each object in the items that were selected by the search. Search syntax is really powerful.

Here is an example of hiding every geometric set in every part in an assembly of arbitrarily large size. Three lines of code. The heavy lifting happens on the first line. You could probably modify this to add your parameters to every part and assembly. Use the GUI search function to figure out your search syntax.

CATIA.ActiveDocument.Selection.Search "'Generative Shape Design'.'Geometrical Set'.Visibility=Shown, all"
CATIA.ActiveDocument.Selection.VisProperties.SetShow catVisPropertyNoShowAttr

BTW, I am a hack macro programmer. Don't listen to me if someone better comes along.

RE: Modify Part Script to Work At Assembly

IMHO selection performs badly on large models.
I've utilized recursion...

Sub CATMain()

Dim ActiveModel
Set ActiveModel = CATIA.ActiveDocument
ActiveModel.Product.ApplyWorkMode DEFAULT_MODE
Dim products1 'As Products
Set products1 = ActiveModel.Product.Products
Dim k As Integer
Dim FullPath As String

For k = 1 To products1.Count

FullPath = products1.item(k).ReferenceProduct.Parent.FullName

If Right(FullPath, 7) = "Product" Then
Call DoTheJob(products1.item(k).ReferenceProduct)
Call Sub_Product(products1.item(k))
ElseIf Right(FullPath, 4) = "Part" Then
Call DoTheJob(products1.item(k).ReferenceProduct)
End If

End Sub

Sub Sub_Product(ActiveModel)

Dim oProducts
Set oProducts = ActiveModel.Products
Dim oProduct
Dim FullPath As String
Dim k As Integer
For k = 1 To oProducts.Count

FullPath = oProducts.item(k).ReferenceProduct.Parent.FullName
If Right(FullPath, 7) = "Product" Then

Call DoTheJob(oProducts.item(k).ReferenceProduct)
Call Sub_Product(oProducts.item(k))

ElseIf Right(FullPath, 4) = "Part" Then
Call DoTheJob(oProducts.item(k).ReferenceProduct)
End If

End Sub

Sub DoTheJob(oProductRefProduct)
Dim UserRefParams As Parameters
Set UserRefParams = oProductRefProduct.UserRefProperties

Dim DetailNum As StrParam
Set DetailNum = UserRefParams.CreateString("DETAIL NUMBER", "")
DetailNum.ValuateFromString ""

Dim Mtrl As StrParam
Set Mtrl = UserRefParams.CreateString("MATERIAL", "")
Mtrl.ValuateFromString ""

Dim StockSize As StrParam
Set StockSize = UserRefParams.CreateString("STOCK SIZE", "")
StockSize.ValuateFromString ""
End Sub


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! Already a Member? Login


eBook - Simulation-Driven Design With SOLIDWORKS
Simulation-driven design can reduce the time and cost of product development. In this engineering.com eBook, we’ll explore how SOLIDWORKS users can access simulation-driven design through the SOLIDWORKS Simulation suite of analysis tools. Download Now
eBook - Integrating the Engineering Ecosystem
Aras Innovator provides multiple options for integrating data between systems, depending on the scenario. Utilizing the right approach to meet specific business requirements is vital. These needs range from authoring tools, federating data from various and dissimilar databases, and triggering processes and workflows. Download Now
Research Report - Simulation-Driven Design for SOLIDWORKS Users
In this engineering.com research report, we discuss the rising role of simulation and the paradigm shift commonly called the democratization of simulation. In particular, we focus on how SOLIDWORKS users can take advantage of simulation-driven design through two analysis tools: SOLIDWORKS Simulation and 3DEXPERIENCE WORKS. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close