Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Part Macro with a Product Active

Status
Not open for further replies.

wdnick

Mechanical
Nov 18, 2013
3
US
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

 
Replies continue below

Recommended for you

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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top