×
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

Running a Part Macro with a Product Active

Running a Part Macro with a Product Active

Running a Part Macro with a Product Active

(OP)
I do 95% of my design work within the context of a product. So I have a CATProduct file open and I'm working in a CATPart that is inside that product.

I have created a macro that will run, but only if a CATPart is active. I know how to open the part in a new window and also to test if a Product or Part is active and have the user open in a new window. I really would like to be able to run this with a CATProduct open though. Is there any way that I can do that?? I'm new to programming Catia, so maybe there is an obvious solution.

Here is the macro as it is written now.

Thanks,
Doug


Sub CATMain()

'error handling
On Error Resume Next

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim parameters1 As Parameters
Set parameters1 = part1.Parameters

Dim ScaleVar1 As Variant
ScaleVar1 = InputBox("Enter Scale Factor.", "Input Box", "Scale Factor")

Dim numericCheck As Boolean
numericCheck = IsNumeric(ScaleVar1)

If numericCheck = False Then
MsgBox "Enter a number!"
End
End If

Dim ScaleFactor1 As Double
ScaleFactor1 = CDbl(ScaleVar1)

Dim realParam1 As RealParam
Set realParam1 = parameters1.CreateReal("", ScaleFactor1#)

realParam1.Rename "Scale Factor"

part1.Update

End Sub

RE: Running a Part Macro with a Product Active

How many parts are in your CATProduct?

If your product structure is always the same, it should be easy, if the part move inside the structure or change name, you should include some selection to identify the part...

Eric N.
indocti discant et ament meminisse periti

RE: Running a Part Macro with a Product Active

I there,

wdnick, I usually work in context as you. So i've done a small trick.

In the assembly context, i need to tell macro, what's the working part. So the main assembly can be the active part, and i can work on a specific part, or I can have an specific active part, and working on it. But I allways need to pick the part.

So what i use:


Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument

Set selection1 = partDocument1.Selection

Dim Status As String
Dim InputObjectType(0)

selection1.Clear


InputObjectType(0) = "Part"


Status = selection1.SelectElement2(InputObjectType, "Seleccione a peça de trabalho", False)
If Status = "Normal" And selection1.Count = 1 Then
Set part1 = selection1.Item(1).Value

Else

MsgBox ("Macro abortada, para executar a acção pretendida volte a seleccionar a Macro")

Exit Sub

End If

'Do something from here
End Sub


The disavantage of this, is that you allways need to pick the part, even if you are only with a CATPart opened.

I hope that i had made some help.

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