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!

Macro for creating Axis Systems

Status
Not open for further replies.

HarunMusic

Computer
Nov 21, 2014
71
BA
Hi, can anyone help me with creating a macro who will create axis systems from sketch. Exmlpe, i ll create sketch with points and than call macro to make Axis System, thx
 
Replies continue below

Recommended for you

I need macro who will create let say 30 axis systems from sketch who have 30 points(befor macro i ll create plane and sketch on it, and i need that z axis is parenculan on that plane) thats all. For example i need to asemble 30 parts, and i m using that created axis.
 
If you want to assemble some parts is good enough to know their position, is not necessary to create axis systems. Just try to record this action in CATIA and you will see. Try also to record action after inserting the part in product (in a specific point or by default), moving to another position and you will understand more.

Regards
Fernando

 
It is for me, i have a lot of reasons why i m using axis systems, thx anyway
 
ub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim axisSystems1 As AxisSystems
Set axisSystems1 = part1.AxisSystems

Dim axisSystem1 As AxisSystem
Set axisSystem1 = axisSystems1.Add()

axisSystem1.OriginType = catAxisSystemOriginByPoint

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")

Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches

Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch.1")

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(sketch1)

axisSystem1.OriginPoint = reference1

axisSystem1.XAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble1(2)
arrayOfVariantOfDouble1(0) = 1#
arrayOfVariantOfDouble1(1) = 0#
arrayOfVariantOfDouble1(2) = 0#
Set axisSystem1Variant = axisSystem1
axisSystem1Variant.PutXAxis arrayOfVariantOfDouble1

axisSystem1.YAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble2(2)
arrayOfVariantOfDouble2(0) = 0#
arrayOfVariantOfDouble2(1) = 1#
arrayOfVariantOfDouble2(2) = 0#
Set axisSystem1Variant = axisSystem1
axisSystem1Variant.PutYAxis arrayOfVariantOfDouble2

axisSystem1.ZAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble3(2)
arrayOfVariantOfDouble3(0) = 0#
arrayOfVariantOfDouble3(1) = 0#
arrayOfVariantOfDouble3(2) = 1#
Set axisSystem1Variant = axisSystem1
axisSystem1Variant.PutZAxis arrayOfVariantOfDouble3

part1.UpdateObject axisSystem1

axisSystem1.IsCurrent = True

part1.Update

Dim settingControllers1 As SettingControllers
Set settingControllers1 = CATIA.SettingControllers

Dim visualizationSettingAtt1 As VisualizationSettingAtt
Set visualizationSettingAtt1 = settingControllers1.Item("CATVizVisualizationSettingCtrl")

visualizationSettingAtt1.SaveRepository

End Sub
 
Your recorded macro is a good starting point. What if you don't have sketch.1 ? Or how do you loop thru points ? Bellow is an example done by me for a Spanish forum (insert an Euler Axis System in a specific point).

Code:
Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part

Dim axisSystems1 As AxisSystems
Set axisSystems1 = part1.AxisSystems
Dim axisSystem1 As AxisSystem
Set axisSystem1 = axisSystems1.Add()
 axisSystem1.Name = "MyAxis"
 
axisSystem1.Type = catAxisSystemEulerAngles

Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
str1 = CATIA.ActiveWindow.Name & "\MyAxis\EulerAngle1"
Dim angle1 As Parameter
Set angle1 = parameters1.Item(str1)
angle1.Value = 45.000000

Dim parameters2 As Parameters
Set parameters2 = part1.Parameters
str2 = CATIA.ActiveWindow.Name & "\MyAxis\EulerAngle2"
Dim angle2 As Parameter
Set angle2 = parameters2.Item(str2)
angle2.Value = 90.000000

Dim parameters3 As Parameters
Set parameters3 = part1.Parameters
str3 = CATIA.ActiveWindow.Name & "\MyAxis\EulerAngle3"
Dim angle3 As Parameter
Set angle3 = parameters3.Item(str3)
angle3.Value = 20.000000

axisSystem1.OriginType = catAxisSystemOriginByPoint
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes
Dim hybridShapePointCoord1 As HybridShape
Set hybridShapePointCoord1 = hybridShapes1.Item("Point.1")

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapePointCoord1)
axisSystem1.OriginPoint = reference1

axisSystem1.XAxisType = catAxisSystemAxisSameDirection
axisSystem1.YAxisType = catAxisSystemAxisSameDirection
axisSystem1.ZAxisType = catAxisSystemAxisSameDirection
part1.UpdateObject axisSystem1

axisSystem1.IsCurrent = True
part1.Update 

End Sub

Regards
Fernando

 
I will always use sketch, i have the sistem of work, for every gropus of parts i create sketch and with sketch i manipulate in xy plane, and sketch is created on plane so i can manipulate with z, when i create Axis System i use only one constraint, and that is constraint betwen that AS and AS in specific part.
 
did you try to use Assembly user pattern if you want to duplicate some part based on a points in a sketch?

Eric N.
indocti discant et ament meminisse periti
 
I dont have manipulation who i want, and its not point on that, point its on macro.
 
hi, i think i am making Progress, i have code here but it wont work any help? i have a lot of preoblems with CreateReferenceFromBRepName
Language="VBSCRIPT"

Sub CATMain()
Set Document = CATIA.ActiveDocument
Set oPart = Document.Part
Set axisSystems1 = oPart.AxisSystems
Set oBody = oPart.Bodies.Item("PartBody")
Set oSketch = oBody.Sketches.Item("Sketch.1")

Set geometricElements1 = oSketch.GeometricElements

For i = 1 To geometricElements1.Count

Set axisSystemi = axisSystems1.Add()
axisSystemi.OriginType = catAxisSystemOriginByPoint
Set referencei = oPart.CreateReferenceFromBRepName("BorderFVertex:(BEdge:(Brp:(Sketch.1;i);None:(Limits1:();Limits2:();+1);Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", sketch1)
axisSystemi.OriginPoint = referencei
axisSystemi.XAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble1(2)
arrayOfVariantOfDouble1(0) = 1.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
axisSystemi.PutXAxis arrayOfVariantOfDouble1

axisSystemi.YAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble2(2)
arrayOfVariantOfDouble2(0) = 0.000000
arrayOfVariantOfDouble2(1) = 1.000000
arrayOfVariantOfDouble2(2) = 0.000000
axisSystemi.PutYAxis arrayOfVariantOfDouble2

axisSystemi.ZAxisType = catAxisSystemAxisByCoordinates

Dim arrayOfVariantOfDouble3(2)
arrayOfVariantOfDouble3(0) = 0.000000
arrayOfVariantOfDouble3(1) = 0.000000
arrayOfVariantOfDouble3(2) = 1.000000
axisSystemi.PutZAxis arrayOfVariantOfDouble3

oPart.UpdateObject axisSystemi

axisSystemi.IsCurrent = False

oPart.Update
Set settingControllers1 = CATIA.SettingControllers
Set visualizationSettingAtt1 = settingControllers1.Item("CATVizVisualizationSettingCtrl")
visualizationSettingAtt1.SaveRepository


Next


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top