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!

Catia Macro - Add geometrical set.

Status
Not open for further replies.

m4the0

Mechanical
Jan 18, 2014
6
PL
Hello, i would like to create macro, which insert new geometrical.set into one selected. I found some examples on internet, and i have created something like this:

Language="VBSCRIPT"
Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part


Set hybridBodies1 = part1.HybridBodies
Set hybridBody2 = hybridBodies1.Add()

hybridBody2.Name = "NEW GEOMETRICAL SET"

part1.InWorkObject = hybridbody2
part1.Update

End Sub

But it inserts geometrical.set into root directory, what should i add to insert geometrical.set into selected geometrical.set.
Is there any posibility to apply hotkey to created macro ?
 
Replies continue below

Recommended for you

Hi,

Should be something like this...

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim oInputType(0)
Dim oStatus
Dim oSelection
Set oSelection = CATIA.ActiveDocument.Selection

	Dim Message, Style, Title, Response, MyString
	Message = ("This macro will a new GS in a selected one."  &_
							(chr(13)) &_
							(chr(13)) &_
						 "	- The active document window must be a CATPart "&_
							(chr(13)) &_
							(chr(13)) &_
"	Do you want to continue ?")
	Style = vbYesNo + vbDefaultButton2    'Define buttons.
	Title = "Purpose "   
	Response = MsgBox(Message, Style, Title)

	If Response = vbNo Then    
		Exit Sub
		Else
	End If

oInputType(0) = "HybridBody"
oStatus = oSelection.SelectElement2(oInputType, "Select a Geometrical Set", True)
If (oStatus = "Cancel") Then
Exit Sub
End If
Set mySelection = oSelection.Item(1).Value

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(mySelection.Name)

part1.InWorkObject = hybridBody1

Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = hybridBody1.HybridBodies

Dim hybridBody3 As HybridBody
Set hybridBody3 = hybridBodies2.Add()

hybridBody3.Name = "NEW_GS"
part1.Update 

End Sub

Regards
Fernando

 
I'm new in Catia scripting so if you could say me how to run it in CATScript instead of catvbs it would be nice :)
I got one extra question, is there any posibility to make this script working when i have CATproduct opened instead of CATPart in new window ?
 
I gather that i have to solve this problem on my own :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top