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!

Count point in Sketch Macro 2

Status
Not open for further replies.

HarunMusic

Computer
Nov 21, 2014
71
BA
Hi, can anyone help me with the macro who will Count Points in CATIA.
I founded this macro who Count sketch based Features, but i dont know how to Count Points, any help
thx

Sub CATMain()
On Error Resume Next

Dim partDoc1 As PartDocument
Set partDoc1 = CATIA.ActiveDocument

If Err.Number <> 0 Then

MsgBox “Active document is not a part document!“”
End

End If
Dim body1 As Body
Set body1 = partDoc1.Part.Bodies.Item(1)

Dim shapes1 As Shapes
Set shapes1 = body1.Shapes

shapecount = shapes1.count

Dim shape1 As Shape
Dim sketchShape As SketchBasedShape
Dim count1 As Integer
count1 = 0

For i = 1 To shapecount

Set sketchShape = shapes1.Item(i)
If Err.Number = 0 Then

count1 = count1 + 1

End If

Err.Clear

Next
MsgBox “Number of sketch based shapes is: ” & count1

End Sub
 
Replies continue below

Recommended for you

I have now other problem, i want now to select Sketch and to count points in that selected sketch, the problem is in this line "Set oSketch =oBody.Sketches.Item("osel.item(1).value.name")" i dont know how to point on that selected sketc any help pls

Sub CATMain()
Set Document = CATIA.ActiveDocument

Dim oPart As Part
Set oPart = Document.Part

Dim oBody As Body
Set oBody = oPart.Bodies.Item("PartBody")

Dim InputObject(0)
Dim oStatus

InputObject(0) = "Sketch"
Set oSel = CATIA.ActiveDocument.Selection
oStatus = oSel.SelectElement2(InputObject, "Select the Sketch", True)

Dim oSketch As Sketch
Set oSketch =oBody.Sketches.Item("osel.item(1).value.name")

Dim geometricElements1 As GeometricElements
Set geometricElements1 = oSketch.GeometricElements

Dim count1 As Integer
count1 = -1

For i = 1 To geometricElements1.Count

If Err.Number = 0 Then

count1 = count1 +1

End If

Next
MsgBox "the number of point is: " & count1



End Sub
 
try without the quotes ????

Set oSketch = oBody.Sketches.Item(osel.item(1).value.name)

______

Alex ,
 
Try..


Set mysketch = Selection.Item(1).Value

Dim oSketch As Sketch
Set oSketch =oBody.Sketches.Item(mysketch.name)





______

Alex ,
 
Im sorry i cant test because i dont have catia anymore..


i use this snippet code... you should try..



Set mysketch = oSel.Item(1).Value

Dim oSketch As Sketch
Set oSketch =oBody.Sketches.Item(mysketch.name)

______

Alex ,
 
The code snippet you are using assumes that the Sketch resides in the MainBody of the CATPart.
oSketch = oSel.Item(1).Value should resolve your issue.

--Doug

 
yeah, it is resolved, thx dougsnell a lot, thx alex, i m happy now :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top