Macro to look inside a geometrical set and generate a mid point on all the curves.
Macro to look inside a geometrical set and generate a mid point on all the curves.
(OP)
Hi any help would be great, im trying to generate a mid point on lots of curves/lines in a geometrical set. I want my macro to search inside the geometrical set named "Geom" and loop through generating a mid point on all the curves and lines in that set.
here's my first attempt and it keeps falling over at this stage: "Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value"
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.Add()
hybridBody2.Name = "Inspection Points"
Dim hybridShapeBoundary1 As HybridShapeBoundary
Dim InputObjectType(0)
Dim SearchSelection As Selection
Dim reference As reference
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim s As Integer
Dim BoundarySelection1 As Selection
Set BoundarySelection1 = partDocument1.Selection
BoundarySelection1.Search "Name=Geom"
Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value
BoundarySelection1.Search "CATGmoSearch.hybridShapeCircleExplicit1,sel"
For s = 1 To BoundarySelection1.Count
Dim BoundarySelection2 As Selection
Set BoundarySelection2 = partDocument1.Selection
BoundarySelection2.Search "Name=Geom"
Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value
BoundarySelection2.Search "CATGmoSearch.hybridShapeCircleExplicit1,sel"
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapeCircleExplicit1.Item2(s).Value)
Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveFromPercent(reference1, 0.500000, False)
hybridBody1.AppendHybridShape hybridShapePointOnCurve1
part1.InWorkObject = hybridShapePointOnCurve1
part1.Update
Next
End Sub
here's my first attempt and it keeps falling over at this stage: "Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value"
CODE --> vb
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.Add()
hybridBody2.Name = "Inspection Points"
Dim hybridShapeBoundary1 As HybridShapeBoundary
Dim InputObjectType(0)
Dim SearchSelection As Selection
Dim reference As reference
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim s As Integer
Dim BoundarySelection1 As Selection
Set BoundarySelection1 = partDocument1.Selection
BoundarySelection1.Search "Name=Geom"
Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value
BoundarySelection1.Search "CATGmoSearch.hybridShapeCircleExplicit1,sel"
For s = 1 To BoundarySelection1.Count
Dim BoundarySelection2 As Selection
Set BoundarySelection2 = partDocument1.Selection
BoundarySelection2.Search "Name=Geom"
Set hybridBody1 = hybridShapeCircleExplicit1.Item2(1).Value
BoundarySelection2.Search "CATGmoSearch.hybridShapeCircleExplicit1,sel"
Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapeCircleExplicit1.Item2(s).Value)
Dim hybridShapePointOnCurve1 As HybridShapePointOnCurve
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveFromPercent(reference1, 0.500000, False)
hybridBody1.AppendHybridShape hybridShapePointOnCurve1
part1.InWorkObject = hybridShapePointOnCurve1
part1.Update
Next
End Sub

RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
Create a new PartDocument and try the following sample.
CODE --> vba
You will notice that the count for selection2 also changes, even though it was only added to selection1.
Selection refers to a single object even though it is assigned to multiple variables.
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
CODE --> vba
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
When running the sample it runs through the mesg box, I select the geoset with the lines/circles in it and nothing happens. The msg box appears then wanting you to select done. Is this because it doesnt recognise the lines/circles as curves? This is when running through as VB script.
when running as a Catscript macro it errors on this line. "Set crvs = New Collection"
Just trying to understand the build up of this vb code.
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
I have never worked on CatScript, so I did not know the difference between VBA and CatScript.
・Collection is not available
・Return value of HybridShapeFactory.GetGeometricalFeatureType method is off by one.
CODE --> CatScript
CatScript is difficult to debug and difficult to develop, so I will not work on it in the future.
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
It works great recognising the lines and generating the midpoints but doesn't seem to recognise curves or circle geometry and thus doesn't create a mid point on those.
Ive tried debugging the code and it errors at " For Each crv In targetCurves" is this a catscript unable to read error?
TIA
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.
CODE -->
regards,
LWolf
RE: Macro to look inside a geometrical set and generate a mid point on all the curves.