Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA v5 CATScript Macros

Status
Not open for further replies.

Sid Pattisapu

Mechanical
Aug 7, 2023
1
Hello, I am fairly new to CATIA v5 Macros. I'm fairly new to Macros in CATIA v5. I'm having trouble Isolating a sketch in CATIA using Macros. Similarly with changing the sketch support. Is there a quick way that I can do both of them?

Thanks

This is my code

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

'-----------------------------Extraction and sketch operation--------------------

Dim sel As Selection
Set sel = partDocument1.Selection

sel.clear

sel.search("..Name='Step.3',All")

Dim extract1 As HybridShapeExtract
Set extract1 = sel.item(1).value

part1.UpdateObject extract1

sel.clear

sel.search("..Name='Step.4',All")

Dim plane1 as AnyObject
Set plane1 = sel.item(1).value

part1.UpdateObject plane1

sel.clear

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim origin As HybridShapePointOnCurve
Set origin = hybridShapeFactory1.AddNewPointOnCurveFromPercent(extract1, 0, False)

origin.Name = "Point.origin"

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()

hybridBody1.Name = "Point"

hybridBody1.AppendHybridShape origin

part1.Updateobject origin


Dim endpt As HybridShapePointOnCurve
Set endpt = hybridShapeFactory1.AddNewPointOnCurveFromPercent(extract1, 1, False)

endpt.Name = "Point.end"

hybridBody1.AppendHybridShape endpt

part1.Updateobject endpt


Dim hax As HybridShapeLinePtPt
Dim Ref1,Ref2 As AnyObject
'Set Ref1 = part1.CreateReferenceFromObject(origin)
'Set Ref2 = part1.CreateReferenceFromObject(endpt)
Set hax = hybridShapeFactory1.AddNewLinePtPt(origin,endpt)

hax.Name = "haxis direction"

hybridBody1.AppendHybridShape hax

part1.Updateobject hax

Dim haxis(2)
hax.GetDirection haxis

sel.Search("..Name='Step.5',All")

Dim sketch1 As Sketch
Set sketch1 = sel.item(1).value

Dim Coord(2)
origin.GetCoordinates Coord

Dim absdata(8)
sketch1.GetAbsoluteAxisData absdata

absdata(0) = Coord(0)
absdata(1) = Coord(1)
absdata(2) = Coord(2)
absdata(3) = haxis(0)
absdata(4) = haxis(1)
absdata(5) = haxis(2)


sketch1.SetAbsoluteAxisData(absdata)

sel.clear

sel.Add sketch1
CATIA.StartCommand "Isolate"

part1.UpdateObject sketch1

sel.clear
'part1.IsolateObject sketch1

'part1.update


End Sub

The SetAbosulteAxisData command sets the sketch where i want it to be but doesnt update the geometric support. Also, the Isolate command doesnt seem to be doing anything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor