macro applying command to selection (several elements)
macro applying command to selection (several elements)
(OP)
hi guys. trying to figure out how to apply a command to several selected elements. i can select several elements without any problem but i'm having issues how then to apply a command to my selection.
do you have any examples of how to do that?
any help will be appreciated.
cheers.
do you have any examples of how to do that?
any help will be appreciated.
cheers.





RE: macro applying command to selection (several elements)
Please be a little bit more specific, there are a lot of different situations (for example a command with or without a dialog box).
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro applying command to selection (several elements)
message box please select contours for disassembling.
now i want to apply disassemble or whatever command to all selected contours.
RE: macro applying command to selection (several elements)
The problem is this only launches the disassemble window but doesn't click the buttons for you...you need user interaction to click the option you want and the ok button...hence the macro will not wait for you to do that.
In theory you would want to loop through all selected objects and perform some task. You may need to add the selected items to collection because the operation you want to perform will not work with multiple objects in the selection.
'Add selected objects to collection
Dim cObjects as Collection
For i = 1 to oSelection.Count
oSelection.Clear
'do something to all the objects
For i = 1 to cObjects.count
Again, this is a bad example because the macro will not wait for you to pick the buttons on the Disassemble window...but hopefully you get the idea
RE: macro applying command to selection (several elements)
RE: macro applying command to selection (several elements)
CATVBS
Sub CATMain()
Dim Seleton
Dim cObject
Dim USelLB
Dim InputObject(0)
Dim oStatus
'Dim oSel As Selection
'Dim oSelItem As Object
Set Selection = CATIA.ActiveDocument.Selection
'Set cObject = CreateObject
InputObject(0) = "AnyObject"'selection filter forces user to select specific objects, AnyObject allows selection of any object
'Set Selection = CATIA.ActiveDocument.Selection
'Set USelLB = USel
Msgbox "PRESS OK AND SELECT ELEMENTS"
Selection.Clear'You should clear the selection before making a selection
oStatus = Selection.SelectElement3(InputObject, "Select objects to list names", True,CATMultiSelTriggWhenUserValidatesSelection, False)
'Add selected objects to collection
Dim cObjects
Set cObject = Selection
For i = 1 to Selection.Count
cObjects.Add Selection.item(i).value
Next
Selection.Clear
'do something to all the objects
For i = 1 to cObjects.count
'add one of the objects to the selection
Selection.Add cObjects.item(i)
'Do something
Catia.StartCommand "Disassemble"
Selection.Clear
Next
End Sub
RE: macro applying command to selection (several elements)
CODE --> catvbs
RE: macro applying command to selection (several elements)
CODE --> vba
Dim Document, Part, SELECTION, Status, sSel
Dim InputObjectType(0)
Set Document = CATIA.ActiveDocument
Set Part = Document.Part
Set SELECTION = Document.SELECTION
SELECTION.Clear
InputObjectType(0) = "AnyObject": iMsg = "Select curves..."
MsgBox "PRESS OK AND SELECT CURVES"
Status = SELECTION.SelectElement3(InputObjectType, iMsg, _
False, CATMultiSelTriggWhenUserValidatesSelection, True)
If ((Status = "Cancel") Or (Status = "Undo") Or (Status = "Redo")) Then Exit Sub
CrCount = SELECTION.Count
For i = 1 To CrCount
'Set SelectedElement = SELECTION.Item(i)
'Set myCurve = SelectedElement.Value
Dim hybridShapeFactory As Factory
Set hybridShapeFactory = Part.hybridShapeFactory
CATIA.StartCommand "Disassemble"
SELECTION.Clear
Next i
End Sub
RE: macro applying command to selection (several elements)
Workaround, in CATScript.
CODE --> CATScript
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro applying command to selection (several elements)
RE: macro applying command to selection (several elements)
If I'm not mistaking there is same number of clicks, just a simple ESC to exit. Anyway, hope you can manage to achieve what you want.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro applying command to selection (several elements)
tried to edit the code a little bit. i can select several curves using select element3 but all curves after disassembling are located in the same geo set. cant figure out how to tell them to go different geo sets.
sorry for too much questions. guys i'm from Israel and we don't have any scripts training in here. the only way is to go abroad. 4 days course like 3 grands not including flight and a hotel
RE: macro applying command to selection (several elements)
RE: macro applying command to selection (several elements)
Thank you lardman.
@JeniaL: There is also no scripting training in my country....I've learned all this stuff on hard way, reading, doing, trying, testing...lot of time lost reading again...and most important learning from advice coming from users like Eric, catiajim, littlechulu, gvi and few others...and I'm still learning from peoples which became more active on the forum in last period.
Funny thing is now I have to do the same thing in Enovia with v6...so you can imagine how I feel...
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: macro applying command to selection (several elements)
RE: macro applying command to selection (several elements)
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU