×
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

Positioned Sketch

Positioned Sketch

Positioned Sketch

(OP)
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

RE: Positioned Sketch

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

Eric N.
indocti discant et ament meminisse periti

RE: Positioned Sketch

(OP)

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

RE: Positioned Sketch

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

RE: Positioned Sketch

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.

RE: Positioned Sketch

@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 --> VBA

Dim Sketch As Sketch
Set Sketch = MySketches.Add (MyPlane) 

Regards,
Drew Mumaw
http://www.textsketcher.com/
http://www.drewmumaw.com/

RE: Positioned Sketch

(OP)
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

RE: Positioned Sketch

@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
http://www.textsketcher.com/
http://www.drewmumaw.com/

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