Positioned Sketch
Positioned Sketch
(OP)
Hej,
What is wrong with my code?
Respect
Santa
What is wrong with my code?
CODE -->
Sub CATMain()
Dim Component As Part
Dim MyDocument As Document
Set MyDocument = CATIA.Documents.Add("Part")
Set Component = MyDocument.Part
Dim part1 As CATBaseDispatch
Set part1 = MyDocument.GetItem("Part1")
part_name = InputBox("Part Name","")
part1.PartNumber = part_name
Dim MySketches As Sketches
Set MySketches = Component.MainBody.Sketches
'-------------------------------------------------------------
Dim HAxis, VAxis As Line2D
Set HAxis = Sketch.AbsoluteAxis.HorizontalReference
Set VAxis = Sketch.AbsoluteAxis.VerticalReference
'-------------------------------------------------------------
Dim OriginElement, MyPlane
Set OriginElement = Component.OriginElements
Set MyPlane = OriginElement.PlaneYZ
Dim Sketch As Sketch
Set Sketch = MySketches.Add (MyPlane)
'Dim Wzk As Factory2D
'Set Wzk = Sketch.OpenEdition
'Sketch.CloseEdition
Component.Update
End Sub Respect
Santa





RE: Positioned Sketch
indocti discant et ament meminisse periti
RE: Positioned Sketch
still something wrong
CODE -->
Sub CATMain() Dim Component As Part Dim MyDocument As Document Set MyDocument = CATIA.Documents.Add("Part") Set Component = MyDocument.Part Dim part1 As CATBaseDispatch Set part1 = MyDocument.GetItem("Part1") part_name = InputBox("Part Name","") part1.PartNumber = part_name Dim MySketches As Sketches Set MySketches = Component.MainBody.Sketches '------------------------------------------------------------- AXIS2D.HorizontalReference As Line2D AXIS2D.Origin As Point2D AXIS2D.VerticalReference As Line2D Dim HAxis, VAxis As Line2D Set HAxis = Sketch.AbsoluteAxis.HorizontalReference Set VAxis = Sketch.AbsoluteAxis.VerticalReference '------------------------------------------------------------- Dim OriginElement, MyPlane Set OriginElement = Component.OriginElements Set MyPlane = OriginElement.PlaneYZ Dim Sketch As Sketch Set Sketch = MySketches.Add (MyPlane) Dim Wzk As Factory2D Set Wzk = Sketch.OpenEdition Dim Line As Line2D Set Line = Wzk.CreateLine (50,50,50,-50) Sketch.CloseEdition Component.Update End SubSanta123
RE: Positioned Sketch
Your problem is likely here because the 'Part1' is going to be incremented the 2nd time you create a CATPart.
Dim part1 As CATBaseDispatch
Set part1 = MyDocument.GetItem("Part1")
The Part Number property is a child of the 'Product' object which can be retrieved from the PartDocument object.
--Doug
RE: Positioned Sketch
You already have:
Set Component = MyDocument.Part
Why do you need part1? Why not just use Component?
As Doug mentioned you can use MyDocument.Product.PartNumber = part_name
If you search the help document for "CAAInfGettingStarted.CATScript" you will get a macro that creates a sketch that defines the horizontal and vertical axis.
RE: Positioned Sketch
The title of your thread is "Positioned Sketch". To the best of my knowledge you cannot create a "positioned sketch" using VBA. All sketches created using VBA are "sliding" and the user would have to change them after the script creates the sketch by defining the positioning. For a sliding sketch the only thing you can specify is the plane on which it will be created. Or in your case:
CODE --> VBA
Regards,
Drew Mumaw
http://www.textsketcher.com/
http://www.drewmumaw.com/
RE: Positioned Sketch
Thanks a lot. My plan was to create a template of Part(just to save some time, creating new Part), but now I don't think it's a good idea. What do You think?
Respect
Santa
RE: Positioned Sketch
Many companies simply use "start parts" to achieve what your after. For example, they have a "start part" (also called a "template" part) that already has certain axis systems and properly named geometrical sets in it. It also might have a solid cavity/core structure already set up for solid modeling. In the case of a sheet metal "start part" it would already have the proper bend radius and sheet metal thickness in accordance with company standards. Any time a new user creates a part they simply choose "new from" rather than File > New.
Regards,
Drew Mumaw
http://www.textsketcher.com/
http://www.drewmumaw.com/