×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

my question about how to draw directly in the opened sketch by macro

my question about how to draw directly in the opened sketch by macro

my question about how to draw directly in the opened sketch by macro

(OP)
I want to write a macro to draw in the current opened sketch, but how to dim the current sketch ,up level part ,document ,their names may be different in different CAtparts ,or some way I have no need to dim them? I am new about macro..

RE: my question about how to draw directly in the opened sketch by macro

CODE --> CATScript

Sub CATMain ()

' New CATPart creationn 
Dim CATPart As Part
Dim Doc As Document
Set Doc = CATIA.Documents.Add ("Part")
Set CATPart = Doc.Part

' Get Sketches  
Dim Sketch As Sketches
Set Sketch = CATPart.MainBody.Sketches

' Reference Plane creation
Dim ReferenceElement, Plane
Set ReferenceElement = CATPart.OriginElements
Set Plane = ReferenceElement.PlaneYZ

' Sketch creation 
Dim Sk As Sketch
Set Sk = Sketch.Add (Plane)

' Sketch edition open 
Dim Wzk As Factory2D
Set Wzk = Sk.OpenEdition

' Geometry creation 
Dim Line As Line2D
Set Line = Wzk.CreateLine (-30, 0, -10, 50)
Line.Construction = False
Set Line = Wzk.CreateLine (-10, 50, 10, 50)
Line.Construction = False
Set Line = Wzk.CreateLine (10, 50, 30, 0)
Line.Construction = False

' Sketch close edition and CATpart update 
Sk.CloseEdition
CATPart.Update

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: my question about how to draw directly in the opened sketch by macro

(OP)
Hi ferdo, thanks for your reply. Maybe I don't express my question clear. My problem is that :

I want to draw some shapes with the macro in a existed sketch(maybe sketch.1 sketch.2 sketch.3 or some another).in other word, begin the macro run I have opened a Catpart or product, and make a sketch(its name is not sure for different part) inwork.

take your codes for example:

Sub CATMain ()

' New CATPart creationn
Dim CATPart As Part
Dim Doc As Document
Set Doc = CATIA.Documents.Add ("Part")
Set CATPart = Doc.Part the part maybe exist in a product, i want the code to get its name automatically;
' Get Sketches
Dim Sketch As Sketches
Set Sketch = CATPart.MainBody.Sketches

' Reference Plane creation
Dim ReferenceElement, Plane
Set ReferenceElement = CATPart.OriginElements
Set Plane = ReferenceElement.PlaneYZ
' Sketch creation
Dim Sk As Sketch
Set Sk = Sketch.Add (Plane) before i run the macro, i have opened the sketch,i want the code to get its name automatically


' Sketch edition open
Dim Wzk As Factory2D
Set Wzk = Sk.OpenEdition

...

RE: my question about how to draw directly in the opened sketch by macro

You said you want to write a macro....that was an example how to do something in sketch...you can continue and post the code here if you will have difficulties in obtaining what you want. But first take a look at documentation. And also search the forum to get other info.

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources