×
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

Modify Part Script to Work At Assembly

Modify Part Script to Work At Assembly

Modify Part Script to Work At Assembly

(OP)
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

Language="VBSCRIPT"

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

Hello,
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.

http://catiavbmacro.com

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.

-or-

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
CATIA.ActiveDocument.Selection.Clear

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
Next

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
Next

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

regards,
LWolf

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

eBook - Efficient and Effective Production Support with 3D Printed Jigs and Fixtures
Jigs and fixtures offer manufacturers a reliable process for delivering accurate, high-quality outcomes, whether for a specific part or feature, or for consistency across multiples of parts. Although the methodologies and materials for producing jigs and fixtures have evolved beyond the conventional metal tooling of years past, their position as a manufacturing staple remains constant due to the benefits they offer. Download Now
Overcoming Cutting Tool Challenges in Aerospace Machining
Aerospace manufacturing has always been on the cutting edge, from materials to production techniques. However, these two aspects of aerospace machining can conflict, as manufacturers strive to maintain machining efficiency with new materials by using new methods and cutting tools. 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