DSESDJ
Aerospace
- May 14, 2024
- 5
Hello all,
Unfortunately my VBA knowledge is limited, especially related to Catia therefore I'm looking for some help in creating a VBA macro for Catia V5.
I'll describe what the macro I have envisioned does:
1. The macro prompts to select a sketch, or geometric set, in which this sketch is located.
2. The macro generates outputs features of all points in this sketch. It also counts the amount of points.
Something like:
CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,sel"
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection.
3. The output points are projected on a surface. Maybe select this surface in earlier stage when prompted to select sketch or geometrical set.
For loop i=1 to objSelection.Count 'iteration over all projected points.
4. Construct a line.(i) through projection point(i), normal to the surface it has been projected on.
5. Create an Axis system.(i), with the origin projection point(i) and z axis direction of line.(i)
Next
Anyone already have a macro that's similar, or is versed in translating above logic into actual code?
In this image I made 1 axis system on Blend.1 at projection.2 using line.2
Recorded code:
Unfortunately this recorded macro works only for this exact coordinates and I need something thats linked to the inputs.
Thanks for reading,
Kind regards,
Sander.
Unfortunately my VBA knowledge is limited, especially related to Catia therefore I'm looking for some help in creating a VBA macro for Catia V5.
I'll describe what the macro I have envisioned does:
1. The macro prompts to select a sketch, or geometric set, in which this sketch is located.
2. The macro generates outputs features of all points in this sketch. It also counts the amount of points.
Something like:
CATIA.ActiveDocument.Selection.Search "CATGmoSearch.Point,sel"
Dim objSelection As Selection
Set objSelection = CATIA.ActiveDocument.Selection.
3. The output points are projected on a surface. Maybe select this surface in earlier stage when prompted to select sketch or geometrical set.
For loop i=1 to objSelection.Count 'iteration over all projected points.
4. Construct a line.(i) through projection point(i), normal to the surface it has been projected on.
5. Create an Axis system.(i), with the origin projection point(i) and z axis direction of line.(i)
Next
Anyone already have a macro that's similar, or is versed in translating above logic into actual code?
In this image I made 1 axis system on Blend.1 at projection.2 using line.2
Recorded code:
Code:
Language="VBSCRIPT"
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
Set hybridShapes1 = hybridBody1.HybridShapes
Set hybridShapeBlend1 = hybridShapes1.Item("Blend.1")
Set reference1 = part1.CreateReferenceFromObject(hybridShapeBlend1)
Set hybridBodies2 = hybridBody1.HybridBodies
Set hybridBody2 = hybridBodies2.Item("Multi Output.1 (Project)")
Set hybridShapes2 = hybridBody2.HybridShapes
Set hybridShapeProject1 = hybridShapes2.Item("Project.2")
Set reference2 = part1.CreateReferenceFromObject(hybridShapeProject1)
Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, -20.000000, 20.000000, False)
hybridBody1.AppendHybridShape hybridShapeLineNormal1
part1.InWorkObject = hybridShapeLineNormal1
part1.Update
Set axisSystems1 = part1.AxisSystems
Set axisSystem1 = axisSystems1.Add()
axisSystem1.OriginType = catAxisSystemOriginByPoint
Set reference3 = part1.CreateReferenceFromObject(hybridShapeProject1)
axisSystem1.OriginPoint = reference3
axisSystem1.XAxisType = catAxisSystemAxisByCoordinates
Dim arrayOfVariantOfDouble1(2)
arrayOfVariantOfDouble1(0) = 0.999990
arrayOfVariantOfDouble1(1) = 0.004416
arrayOfVariantOfDouble1(2) = 0.000000
axisSystem1.PutXAxis arrayOfVariantOfDouble1
axisSystem1.YAxisType = catAxisSystemAxisByCoordinates
Dim arrayOfVariantOfDouble2(2)
arrayOfVariantOfDouble2(0) = -0.004246
arrayOfVariantOfDouble2(1) = 0.961457
arrayOfVariantOfDouble2(2) = -0.274924
axisSystem1.PutYAxis arrayOfVariantOfDouble2
axisSystem1.ZAxisType = catAxisSystemAxisSameDirection
Set reference4 = part1.CreateReferenceFromObject(hybridShapeLineNormal1)
axisSystem1.ZAxisDirection = reference4
part1.UpdateObject axisSystem1
axisSystem1.IsCurrent = True
part1.Update
Set settingControllers1 = CATIA.SettingControllers
Set visualizationSettingAtt1 = settingControllers1.Item("CATVizVisualizationSettingCtrl")
visualizationSettingAtt1.SaveRepository
End Sub
Unfortunately this recorded macro works only for this exact coordinates and I need something thats linked to the inputs.
Thanks for reading,
Kind regards,
Sander.