Welcome to the COE Discussion Forums! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.


COE Community News

Follow COE on

COE DISCUSSION FORUM
Sketch on solid planar face?
Last Post 25 Feb 2010 06:28 PM by nbettin. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
nbettin
New Member
New Member
Posts:57

--
08 Feb 2010 10:12 PM  

I've looked hard and experimented plenty but can't seem to get a sketch to position actually on the user-selected planar face. It seems like the sketch's support plane is parallel to the selected surface but running through the part's origin. Documentation indicates this would be the case too from what I can tell, but it also indicates that it is possible to place a sketch actually on the selected planar face. But the it's not clear that this can be done with VB. "Using a reference allows to create a sketch either on an element, as here the XY plane, or on a solid planar face that is not directly accessible as a VB object."

I have a simple pad, the user is prompted to select a surface, the surface is selected and the macro creates a geoset, sketch, and line geometry. But the sketch is created in the Z=0 plane and not in the plane on 'top' of the pad, the surface that was selected at Z=1.0. Is this as good as it gets using VBA to do this? Funny thing is I have a Powercopy that performs this function well. The user selects a surface and point and the sketch is inserted there. I'm trying to replicate this in VB or VBA and add some functinality that can't be accomplished with a Powercopy. ASSuming there is a way to accomplish sketching on a solid planar face my next problem will be moving the sketch origin around in that plane.

This is the code portion that is relevant;

Dim status As String
Dim filter(0)

filter(0) = "PlanarFace"

status = sel.SelectElement2(filter, "Select Plane", False)

...

Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches

Dim reference1 As Reference

Set reference1 = sel.Item(1).Value

Dim sketch1 As Sketch
Set sketch1 = sketches1.Add(reference1)

Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0#
arrayOfVariantOfDouble1(1) = 0#
arrayOfVariantOfDouble1(2) = 0#
arrayOfVariantOfDouble1(3) = 0#
arrayOfVariantOfDouble1(4) = 1#
arrayOfVariantOfDouble1(5) = 0#
arrayOfVariantOfDouble1(6) = -1# 'always point in negative x direction
arrayOfVariantOfDouble1(7) = 0#
arrayOfVariantOfDouble1(8) = 0#

Set sketch1Variant = sketch1
sketch1Variant.SetAbsoluteAxisData arrayOfVariantOfDouble1

myPart.InWorkObject = sketch1

Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()

Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements

Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis"

Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection"

line2D1.ReportName = 1

Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection"

line2D2.ReportName = 2

 

MBERRY
Basic Member
Basic Member
Posts:470

--
11 Feb 2010 12:50 PM  
Ahhh...you are so close! When you retrieve an SelectedElement object from the selection, there are 2 different properties that refer to that selected item (.Value and .Reference) Value returns the actual object itself and .Reference returns a special reference object that refers to it. In this case you need the latter.

Also, unless you are using a pretty old release of CATIA, the Selection.Item method has been deprecated, try to use .Item2 method instead. The Item method is still there, but it may not always work correctly.

Just change this one line of code...

Set reference1 = sel.Item2(1).Reference

-Mike
nbettin
New Member
New Member
Posts:57

--
11 Feb 2010 11:33 PM  
Thanks for the help Mike, but there was no change in the result. Is there something I can Watch that will show these properties. I Watched the selection and the reference1 but there isn't much meaningful info there that I can see.

Maybe that's what the help document means where it says,
Using a reference allows to create a sketch either on an element, as here the XY plane, or on a solid planar face that is not directly accessible as a VB object."
?
MBERRY
Basic Member
Basic Member
Posts:470

--
12 Feb 2010 01:32 PM  
Sorry, I'm not sure what is going on there...As far as I can see your code looks ok and it works fine for me in R18. Maybe you are on a different release? If all else fails when I get some weird behavior I can't explain with V5, I reset all CATSettings (or delete them from the folder) then restart.

That help document text is just making a general statement about using reference objects. Whenever you create a new geometrical feature from some other geometry, you always have to refer to that parent geometry using a reference object. Nothing different here with sketches, it's the same case for any geometry. You can get a reference object from a SelectedElement object (like you are above) or by using Part.CreateReferenceFrom...

-Mike
nbettin
New Member
New Member
Posts:57

--
25 Feb 2010 06:28 PM  

Ok, after looking at this in more detail I've found that I am able to create a sketch on the surface of a part in a product as long as that part was the first part in my product. Seems like the way the product was built affects the outcome.

Any ideas on this?

For others...below is the the vb.net code for doing this...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim CATIA As INFITF.Application
CATIA = GetObject(, "CATIA.Application"

'Get all the open documents
Dim myDocuments As Documents
myDocuments = CATIA.Documents

Dim myProductDocument As ProductDocument
myProductDocument = myDocuments.Item(1)

Dim myProduct As Product
myProduct = myProductDocument.Product

Dim myPartProduct As Product
myPartProduct = myProduct.Products.Item(1)

Dim myPartDocument As PartDocument
myPartDocument = myDocuments.Item(myPartProduct.PartNumber & ".CATPart"

Dim myPart As Part
myPart = myPartDocument.Part

Dim myDocument As Document
myDocument = CATIA.ActiveDocument

Dim myHybridBodies As HybridBodies
myHybridBodies = myPart.HybridBodies

Dim myHybridBody As HybridBody
myHybridBody = myHybridBodies.Add

'retrieve the Open body of the part
myHybridBody = myHybridBodies.Item(1) 'this adds an empty geoset
Dim hybridShapes1 As HybridShapes
hybridShapes1 = myHybridBody.HybridShapes

Dim sel 'As Selection
sel = myPartDocument.Selection
Dim status As String
Dim filter(0)
filter(0) = "PlanarFace"

status = sel.SelectElement2(filter, "Select Plane", False)

If status = "Cancel" Then
MsgBox("Selection Canceled"
Exit Sub
End If

myHybridBody.Name = "Forward Arrow"
myHybridBody = myHybridBodies.Item("Forward Arrow"

myPart.Update()

Dim mySketches As Sketches
mySketches = myHybridBody.HybridSketches

'Dim myOriginElements As OriginElements
'myOriginElements = myPart.OriginElements

Dim myReference As Reference
'myReference = myOriginElements.PlaneXY
myReference = sel.Item2(1).Reference

Dim mySketch As Sketch
mySketch = mySketches.Add(myReference)

Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 1.0#
arrayOfVariantOfDouble1(1) = 0.0#
arrayOfVariantOfDouble1(2) = 0.0#
arrayOfVariantOfDouble1(3) = 0.0#
arrayOfVariantOfDouble1(4) = 1.0#
arrayOfVariantOfDouble1(5) = 0.0#
arrayOfVariantOfDouble1(6) = -1.0# 'always point in negative x direction
arrayOfVariantOfDouble1(7) = 0.0#
arrayOfVariantOfDouble1(8) = 0.0#

Dim mySketchVariant As Sketch
mySketchVariant = mySketch
mySketchVariant.SetAbsoluteAxisData(arrayOfVariantOfDouble1)

myPart.InWorkObject = mySketch

Dim myFactory2D As Factory2D
myFactory2D = mySketch.OpenEdition()

Dim myGeometricElements As GeometricElements
myGeometricElements = mySketch.GeometricElements

Dim myAxis2D As Axis2D
myAxis2D = myGeometricElements.Item("AbsoluteAxis"

Dim myLine2D As Line2D
myLine2D = myAxis2D.GetItem("HDirection"
myLine2D.ReportName = 1

Dim myLine2D2 As Line2D
myLine2D2 = myAxis2D.GetItem("VDirection"
myLine2D2.ReportName = 2

'Create arrow vertex points clockwise order
'Origin point
Dim myPoint2D As Point2D
myPoint2D = myFactory2D.CreatePoint(0.0#, 0.0#)
myPoint2D.ReportName = 3

'Rightmost point
Dim myPoint2D2 As Point2D
myPoint2D2 = myFactory2D.CreatePoint(20.0#, -20.0#)
myPoint2D2.ReportName = 4

Dim myPoint2D3 As Point2D
myPoint2D3 = myFactory2D.CreatePoint(6.6, -20.0#)
myPoint2D3.ReportName = 5

Dim myPoint2D4 As Point2D
myPoint2D4 = myFactory2D.CreatePoint(6.6, -26.6)
myPoint2D4.ReportName = 6

Dim myPoint2D5 As Point2D
myPoint2D5 = myFactory2D.CreatePoint(-6.6, -26.6)
myPoint2D5.ReportName = 7

Dim myPoint2D6 As Point2D
myPoint2D6 = myFactory2D.CreatePoint(-6.6, -20.0#)
myPoint2D6.ReportName = 8

'Leftmost point
Dim myPoint2D7 As Point2D
myPoint2D7 = myFactory2D.CreatePoint(-20.0#, -20.0#)
myPoint2D7.ReportName = 9

'Draw lines from point to point, clockwise order
Dim myLine2D3 As Line2D
myLine2D3 = myFactory2D.CreateLine(0.0#, 0.0#, 20.0#, -20.0#)
myLine2D3.ReportName = 10
myLine2D3.StartPoint = myPoint2D
myLine2D3.EndPoint = myPoint2D2

Dim myLine2D4 As Line2D
myLine2D4 = myFactory2D.CreateLine(20.0#, -20.0#, 6.6, -20.0#)
myLine2D4.ReportName = 11
myLine2D4.StartPoint = myPoint2D2
myLine2D4.EndPoint = myPoint2D3

Dim myLine2D5 As Line2D
myLine2D5 = myFactory2D.CreateLine(6.6, -20.0#, 6.6, -26.6)
myLine2D5.ReportName = 12
myLine2D5.StartPoint = myPoint2D3
myLine2D5.EndPoint = myPoint2D4

Dim myLine2D6 As Line2D
myLine2D6 = myFactory2D.CreateLine(6.6, -26.6, -6.6, -26.6)
myLine2D6.ReportName = 13
myLine2D6.StartPoint = myPoint2D4
myLine2D6.EndPoint = myPoint2D5

Dim myLine2D7 As Line2D
myLine2D7 = myFactory2D.CreateLine(-6.6, -26.6, -6.6, -20.0#)
myLine2D7.ReportName = 14
myLine2D7.StartPoint = myPoint2D5
myLine2D7.EndPoint = myPoint2D6

'Leftmost point
Dim myLine2D8 As Line2D
myLine2D8 = myFactory2D.CreateLine(-6.6, -20.0#, -20.0#, -20.0#)
myLine2D8.ReportName = 15
myLine2D8.StartPoint = myPoint2D6
myLine2D8.EndPoint = myPoint2D7

Dim myLine2D9 As Line2D
myLine2D9 = myFactory2D.CreateLine(-20.0#, -20.0#, 0.0#, 0.0#)
myLine2D9.ReportName = 16
myLine2D9.StartPoint = myPoint2D7
myLine2D9.EndPoint = myPoint2D

mySketch.CloseEdition()

myPart.InWorkObject = myHybridBody

myPart.Update()
End Sub

You are not authorized to post a reply.

Active Forums 4.1