Continue to Site

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!

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

Status
Not open for further replies.

Arichzhy

Automotive
Aug 20, 2016
8
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..
 
Replies continue below

Recommended for you

Code:
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

- Romania
- EU
 
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 [highlight #4E9A06]the part maybe exist in a product, i want the code to get its name automatically;[/highlight]
' 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) [highlight #4E9A06]before i run the macro, i have opened the sketch,i want the code to get its name automatically
[/highlight]

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

...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor