Macro
Macro
(OP)
I just bought the Emmett Ross book VB Scripting for CATIA V5 & i'm slowly working my way through learning macros.
I'm trying to create a macro that will Modify a set of points with a coordinate point type definition by a set value.
My Goal would be:
1) Macro looks at whatever geometric set is active
2) Macro would mofify all points in that parts geometric set by 5x, 5y, or 5z.
Something like that is my goal. If anyone has any input or parts of other macro's that would contain some helpful chunks or code, anything to help out would be greatly appreciated. I'm really looking forward to learning more about macro's.
Eventually I hope to get good enough to have a form or GUI created that would allow me to manually add the inputs outside of the source code in the macro having it predefined. One step at a time though :) I haven't used VB is about 15 years, so i'm pretty rusty.
Thanks again for any input.
I'm trying to create a macro that will Modify a set of points with a coordinate point type definition by a set value.
My Goal would be:
1) Macro looks at whatever geometric set is active
2) Macro would mofify all points in that parts geometric set by 5x, 5y, or 5z.
Something like that is my goal. If anyone has any input or parts of other macro's that would contain some helpful chunks or code, anything to help out would be greatly appreciated. I'm really looking forward to learning more about macro's.
Eventually I hope to get good enough to have a form or GUI created that would allow me to manually add the inputs outside of the source code in the macro having it predefined. One step at a time though :) I haven't used VB is about 15 years, so i'm pretty rusty.
Thanks again for any input.





RE: Macro
You need to specify more...
Do you work in a part or a product? Do you want to create the macro in a CATScript or catvba (I suppose you want to be in a catvba since you want a GUI)? Or maybe do you want to create the macro working with CATIA from an EXCEL file (code in EXCEL)? Do you want to be able to select a GS or this GS does have a specific name and can be specified in code?
Anyway, check also this link
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro
And yea I am trying to do it in a catvba.
I didn't know anything about a code from excel. Running it just from CATIA directly would be just fine. I'm pretty open to whatever idea's people can share.
I would like to try to make the macro be ran on the geometric set i select. Worse can scenareo I could try to make all the geometric sets named the same thing, but a selection would be prefered as right now all the geometric sets are named different things.
Thanks for the link also.
RE: Macro
Did you tried something?
There are a lot of possibilities to run code to do something in CATIA from any application which has vba (Excel, PowerPoint...), vbs, html, Java,vb.net, C....
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro
I have been able to get a macro to create new points & move them + a determined amount. But not move an existing point.
The logic would be.
1) User Select a Geometric Set in a CatPart
2) Move 1st point in geometric set by value x
3) Move 2nd Point in geometric set by value x
4) Repeat for all points in the geometric set
Eventually once I get that figured out, I can work to make a form where I can enter the value, but until then.. it can be predefined in the code.
I tried to figure it out with the macro recorder, but it only comes up with creating a new point.
RE: Macro
Bellow is a solution in CATScript, it would be great if you can show us your catvba with form, maybe inspired from what I'm posting here (but not necessary, a problem can be solved in few ways from my experience) .
CODE --> CATScript
Language="VBSCRIPT" Sub CATMain() Dim oPartDoc As Part On Error Resume Next Set oPartDoc = CATIA.ActiveDocument.Part If Err.Number <> 0 Then Message = MsgBox("Sorry, this script works with a CATPart as Active document", vbCritical, "Error") Exit Sub End If ' What do you want to select Dim EnableSelectionFor(0) EnableSelectionFor(0) = "HybridBody" ' Reset the Selection Set sSEL = CATIA.ActiveDocument.Selection sSEL.Clear ' Define Selection MsgBox "Please select the Geometrical Set where you have the points" UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Please select another Geometrical Set", False) ' Evaluation if the selection is correct or not If UserSelection <> "Normal" Then MsgBox "Error with the selection" Exit Sub Else '''''''''''''''''''''''''''''''input values for new x,y,z coord, this should be completed, clicking on Cancel is not working Dim new_x As Double new_x = "5" new_x = InputBox ("Please enter value for scaling x coordinate" , "scale x coord point", new_x) Dim new_y As Double new_y = "5" new_y = InputBox ("Please enter value for scaling y coordinate" , "scale y coord point", new_y) Dim new_z As Double new_z = "5" new_z = InputBox ("Please enter value for scaling z coordinate" , "scale z coord point", new_z) ''''''''''''''''''''''''''''''' End If Set ohybridbody = sSEL.Item(1).Value Set partDocument1 = CATIA.ActiveDocument Dim selection1 As Selection Set selection1 = partDocument1.Selection selection1.Search "CATPrtSearch.Point,sel" ''''''''''''''''''''''''''''''''A loop to go thru each selected points and change it's name, just for fun intNbSelected = selection1.Count2 If intNbSelected > 0 Then For intIndex = 1 to intNbSelected selection1.Item2(intIndex).Value.Name = "Point." &intIndex Next End If ''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' New Geometrical Set where where points will be created Set part1 = partDocument1.Part Set hybridBodies1 = part1.HybridBodies Set hybridBody1 = hybridBodies1.Add() Set hybridShapeFactory1 = part1.HybridShapeFactory ''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' Here we are geting the old coord values Dim listOfTypes(1) listOfTypes(1)="Point" Dim myDocument Set myDocument = CATIA.ActiveDocument Dim mySelection As Selection Set mySelection = myDocument.Selection Dim number number = mySelection.Count MsgBox "Number of selected points: "& number 'Control message, better to comment after testing Dim oPointCoord(2) as CATSafeVariant Dim oSelElem as Object Dim selectedElement As SelectedElement For i=1 to number Set selectedElement = mySelection.Item(i) MsgBox selectedElement Set oSelElem = mySelection.Item(I) oSelElem.Value.GetCoordinates (oPointCoord) ''''''''''''''''''''''''''''''new coord values x=oPointCoord(0)*new_x y=oPointCoord(1)*new_y z=oPointCoord(2)*new_z MsgBox "Old coord - " & oPointCoord(0) & ";" & oPointCoord(1) & ";" & oPointCoord(2) & vbCrlf & "New coord - " & x & ";" & y & ";" & z 'Control message, better to comment after testing ''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' Here we are creating new points with the new coord values Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(x, y, z) hybridBody1.AppendHybridShape hybridShapePointCoord1 part1.InWorkObject = hybridShapePointCoord1 part1.Update Next End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro
Thank you and when I can get more in depth with it I will share more also. I will work to do it with a form & hopefully can make it work soon. Thank you
RE: Macro
RE: Macro
And by the way, some workbenches are more "friendly" than others , so don't be surprised if you will get nothing in recorder
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro
The problem is that the original points have other parts that are contextually linked to them. So they must be the same point. The code you provided was a great start though and much of the stuff is very very useful.
RE: Macro
That's another story...I didn't understood this, sorry.
Anyway, happy coding
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...