Welcome to the COE Discussion Forum! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.

 

The COE 2008 Fall Industry Workshops

Experience two days of industry-focused education and hands-on training on the Dassault PLM solutions suite of products.  All education featured at the workshop is developed by and for users of CATIA®, ENOVIA®, DELMIA® and SIMULIA®.
 

Automotive
Oct. 15-16
Troy, Michigan

Aerospace & Defense
Oct. 27-28
Wichita, Kansas


Forum Highlight: CATIA V6

 

Get Answers to Your V6 Questions
Dassault Systèmes answers user questions about CATIA V6.  Discuss these answers and propose new questions with end users from around the world in the CATIA V6 Forum.

COE DISCUSSION FORUM
Subject: TOTAL BEGINNER @ MACROS

You are not authorized to post a reply.   
Author Messages
COE-FORUM-USER

27 May 2005 01:11 PM

Being a total beginner at macros I dont know where to start.
Most posts dealing with such matters look like
they are written in another language lol.

If I wanted to make a simple macro for a blend surface
for example , how do you do that ?

How do you set the macro to pause and ask
for the lines to pick.........
It seems Im able to record a macro but
after that ....FORGET ABOUT IT !

Thanks to anyone brave enough
to help this poor soul
CARBAHOLIC

27 May 2005 03:59 PM
I would say start even simpler than that. I would start by just creating a line from two points. Here's an example.

Language="VBSCRIPT"

Sub CATMain()

'An apostraphe lets you write a comment
'A part Document is and instance of CATIA
'Here I will grab the one that's already open
Set MyPartDocument = CATIA.ActiveDocument

'Now I will select the part that I'm working on right now
Set MyPart = MyPartDocument.Part

'HybridShapeFactory contains all of the functions to create new points, lines, and surfaces (stuff in GSD)
Set MyHybridShapeFactory = MyPart.HybridShapeFactory

'In Order to Pick the Hybrid Body I want, first I need to distinguish that that's the type of element I'm looking for
Set MyHybridBodies = MyPart.HybridBodies

'Get The Hybrid Body **You'll have to change the name to whatever your geometrical set is named
Set MyHybridBody = MyHybridBodies.Item("EnterGeometricalSetNameHere")

'Hybridbody elements that already exist will be found in hybridshapes
Set MyHybridShapes = MyHybridBody.HybridShapes

'Create Objects from the two points you are going to use
Set object1 = MyHybridShapes.Item("EnterNameOfFirstPointHere")
Set object2 = MyhybridShapes.Item("EnterNameOfFirstPointHere")

'Now Turn Those Objects into References
Set reference1 = MyPart.CreateReferenceFromObject(object1)
Set reference2 = MyPart.CreateReferenceFromObject(object2)

'Now We can finally create a line
Set Line1 = MyHybridShapeFactory.AddNewLinePtPt(reference1, reference2)

'Even though You have created the Line, We still need to actually add it to the tree
MyHybridBody.AppendHybridShape Line1

'And Finally, Update the Part
MyPart.Update

End Sub

Hopefully messing around with this can help you get an idea of what are command and what are variables and a little bit of how CATIA works.

the function that lets you pick a line is selectelement2, but it is far from the easiest function to use.

You'll find that if you record a macro, and then delete the part that you just recorder, and then run the macro again it will make exactly the same part in exactly the same way. all the recording function is really good for is to get an idea of how CATIA does things. It can make a good base to start a working macro from, but that's it.
CRAIG HELM


29 May 2005 08:02 PM
Yeah, you are definitely starting very very deep. I wouldn't recommend that at all.
Look at the selectelement2 method to do this.

Have you programmed before? Are you "proficient" or at least feel comfortable writing code in that language? If both these are yes, then you should be able to look through the api references and figure most of this stuff out. If one of those is no, then I would say pay for a course to learn vba in catia. If you don't mind going slower and know excel, then start with vba for excel. This will be much cheaper on the pocket book, but it will take longer to learn.

If you just want a few scripts here and there, then you might just want to contract those out if you are a smaller company. If you are a bigger company, pay someone full-time to do this stuff as it will pay off greatly!

Let us know if you have any more questions.

Also, this forum is also a great place to get answers, even if sometimes those answers are you can't do that, or don't do that.

-craig helm
Catia V5 R16 | Windows XP SP2 | Intel P4 3.4GHz | 2GB RAM | ATI FireGL V3100 128 MB DDR
IPHILLIPS

27 Jul 2005 01:54 AM
The comment:
'Even though You have created the Line, We still need to actually add it to the tree
Does this mean that if I do not add it to the tree it will be discarded at the end like a V4 temporary element?

Ian

PS: For nostalgia purposes, the equivalent in V4 IUA is much shorter than VBScript. Thus easier for beginners and non full time programmers. The "selection" especially is a piece of cake!

*-------------Declare Variables ---------
LN LN
PT PT1
PT PT2
*---------------------------------------------
PROC
MSGCNTL "CREATE A LINE PT PT"
LABEL NEXT
SELECT "SELECT PT1",PT1,NO,YES
IF (IRET = YES) BRANCH END
HIGHLT PT1
SELECT "SELECT PT2",PT2,NO
LOAD GICLN2P 1,PT1,PT2,LN,IER
BRANCH NEXT
LABEL END
END

Ian Phillips. FORCEFIVE AG, Munich, Germany
COE-FORUM-USER

27 Jul 2005 03:09 AM
I don't know what you mean about VB being long-winded. I can generate a fully associative, parametric line in 8 lines of code (it may have wrapped as a result of the window so I've included line numbers):

1 - Sub CATMain()
2 - Set Fact = CATIA.ActiveDocument.Part.HybridShapeFactory
3 - Set p1 = Fact.AddNewPointCoord(0, 0, 0)
4 - Set p2 = Fact.AddNewPointCoord(10, 0, 0)
5 - CATIA.ActiveDocument.Part.HybridBodies.Item(1).AppendHybridShape Fact.AddNewLinePtP(CATIA.ActiveDocument.Part.CreateReferenceFromObject(p1), _
6 - CATIA.ActiveDocument.Part.CreateReferenceFromObject(p2))
7 - CATIA.ActiveDocument.Part.Update
8 - End Sub


I could have made it smaller but that would be silly

Now remember everyone, I'm just joking. I don't really recommend coding like this (beginner or not), but I couldn't resist a little bit of "my language is better than yours...".




By the way you can create temporary elements by not adding them to the tree. I'm not sure if this can cause Catia to become unstable or consume extra memory without releasing it, but it is a nice trick, particularly for measures.
CRAIG HELM


27 Jul 2005 07:07 AM
Yeah, there are three options for elements,
1) Create the element
2) Compute it (can be used later for computations, but not placed in the tree)
3) Add it (It is just like anything else added to the tree)

-craig helm
Catia V5 R16 | Windows XP SP2 | Intel P4 3.4GHz | 2GB RAM | ATI FireGL V3100 128 MB DDR
IPHILLIPS

28 Jul 2005 06:23 PM
Jack
Well done! The challenge is now to beat your 8 lines! Anyone?
Yours is also helpful to see the various steps.
But why are the "normal" ones so long winded?

I still have a problem with the length of those words compared to IUA.
And it is also long winded when it comes to selection. In my IUA I included the full V4 type Point selection and looped it create as many lines as the user selects pairs of points.

But enough of V4, I still want to know what happens when the feature is NOT added to the tree. Does it have to be added before it can be used by another feature? and what does Compute it mean? create it?

Ian Phillips. FORCEFIVE AG, Munich, Germany
CRAIG HELM


29 Jul 2005 07:48 AM
I can name that tune in 2 lines.

If you don't do anything after creating the feature, then you can't use it. Computing it kinda puts it in limbo. You can use it (I think only with code and it probably goes out with the rest of the cleanup when the code finishes, I've never really checked), but you can't see it in catia.


-craig helm
Catia V5 R16 | Windows XP SP2 | Intel P4 3.4GHz | 2GB RAM | ATI FireGL V3100 128 MB DDR
IPHILLIPS

01 Aug 2005 07:18 AM
Thanks Craig

And now the Update bit: CATIA.ActiveDocument.Part.Update
Does it belong right at the end of a script or is there a reason to update earlier?


Ian Phillips. FORCEFIVE AG, Munich, Germany
JSTRAWN


01 Aug 2005 07:41 AM
Depends. If you have created some geometry and need to use it in the next piece of your script, you either need to update it or to compute it.

Jim Strawn
Cessna Aircraft Co.
CRAIG HELM


02 Aug 2005 07:05 PM
Another thing would be for time reasons. You may have a bunch of things that you are unsure about and want to check them one by one. I had a program that created thousands of lines and stuff, so I periodically updated to make sure everything was going well. Then you can exit the code or some other operation if things fail.

-craig helm
Catia V5 R16 | Windows XP SP2 | Intel P4 3.4GHz | 2GB RAM | ATI FireGL V3100 128 MB DDR
You are not authorized to post a reply.
Forums > COE Forums > KBE > TOTAL BEGINNER @ MACROS



ActiveForums 3.6

    

401 North Michigan Avenue, Chicago, IL 60611-4267 | (312) 321-5153 | (800) COE-CALL (U.S.)