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 SubRegards
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
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
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU