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!

Positioned Sketch

Status
Not open for further replies.

Santa123

Mechanical
Oct 2, 2006
80
PL
Hej,

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
 
Replies continue below

Recommended for you

can't create an empty sketch... you need geometry in your sketch

Eric N.
indocti discant et ament meminisse periti
 

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 Sub

Santa123
 
Knowing which line you are getting the error on would be helpful.

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
 
Where does the macro fail?

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.
 
@Santa123
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:
Dim Sketch As Sketch
Set Sketch = MySketches.Add (MyPlane)

Regards,
Drew Mumaw
 
hej drewmumaw,

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
 
@Santa123
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top