All Frameworks Object Hierarchy This Framework Indexes
+--------+ !Product3! +--------+ ! +- Product2 (Product2.1) ! ! ! +- Product1 (Product1.1) ! ! ! +- Part1 (Part1.1) ! ! ! +- Part1 ! ! ! +- PartBody ! ! +------------------+ ! +- Pad.1 ! Selected feature ! ! ! +------------------+ ! +- Sketch.1 +- Part2 (Part2.1)For a given selected feature, its parent objects which are exposed to automation can be accessed through a recursive call to the AnyObject.Parent property. When a given feature is selected, there are three possibilities:
Set ActiveProductDocument = CATIA.ActiveDocument Set Product3 = ActiveProductDocument.Product Set Product3Products = Product3.Products Set Product2Dot1 = Product3Products.Item("Product2.1") : Set Product2 = Product2Dot1.ReferenceProduct Set ProductDocument2 = Product2.Parent Set Product2Products = Product2.Products Set Product1Dot1 = Product2Products.Item("Product1.1") : Set Product1 = Product1Dot1.ReferenceProduct Set ProductDocument1 = Product1.Parent Set Product1Products = Product1.Products Set Part1Dot1 = Product1Products.Item("Part1.1") : Set Part1 = Part1Dot1.ReferenceProduct Set PartDocument1 = Part1.Parent Set Selection = ActiveProductDocument.SelectionAnother Selection object, such as:
Set ProductDocument2Selection = ProductDocument2.Selection Set ProductDocument1Selection = ProductDocument1.Selection Set PartDocument1Selection = PartDocument1.Selection(lets take ProductDocument2Selection for example) can only be used if, among the different Window , there is at least one whose root Document is ProductDocument2 . Otherwise, results are unpredictable.
o Property Count2( | ) As (Read Only) |
o Property Count( | ) As (Read Only) |
o Property VisProperties( | ) As (Read Only) |
Dim Selection,VisPropertySet Set Selection = CATIA.ActiveDocument.Selection Set VisPropertySet = Selection.VisProperties VisPropertySet.SetShow catVisPropertiesNoShowAttr
o Sub Add( | iObject) |
CATIA.ActiveDocument.Selection.Add(ObjectToAdd)
o Sub Clear( | ) |
CATIA.ActiveDocument.Selection.Clear()
o Sub Copy( | ) |
CATIA.ActiveDocument.Selection.Copy()
o Sub Cut( | ) |
CATIA.ActiveDocument.Selection.Cut()
o Sub Delete( | ) |
CATIA.ActiveDocument.Selection.Delete()
o Func FilterCorrespondence( | iFilterType) As |
Dim Document,Part,Selection,ShapeFactory,EdgeSaveAllocatedCount,EdgeIndex,AllEdgesHaveBeenSelected,AllFit Dim EdgeSaveCount,SelectedEdge,SelectedElementBelongsToSaveVariables,AlreadySelectedEdgeIndex Dim OtherEdgeAnswer,Fillet Set Document = CATIA.ActiveDocument : Set Part = Document.Part : Set Selection = Document.Selection Set ShapeFactory = Part.ShapeFactory ReDim InputObjectType(0) : InputObjectType(0)="TriDimFeatEdge" : EdgeSaveCount = 0 'We determine if the selection contains an object which is not a TriDimFeatEdge element AllFit = Selection.FilterCorrespondence(InputObjectType) 'If the selection contains an object which is not a TriDimFeatEdge element, we clear the selection if (Not AllFit) then Selection.Clear EdgeSaveAllocatedCount = Selection.Count+10 : ReDim EdgeSave(EdgeSaveAllocatedCount-1) 'We loop onto interactive selections AllEdgesHaveBeenSelected = false do while (Not AllEdgesHaveBeenSelected) ' We save the selection content in save variables. ' This corresponds to the fact that: ' - we want that, during the following call to SelectElement2, the TriDimFeatEdge elements previously selected ' remain highlighted ' - this is done using the False value for the iObjectSelectionBeforeCommandUsePossibility ' parameter of the SelectElement2 method, the selection containing the TriDimFeatEdge elements. It requires that ' the selection content be saved if (EdgeSaveAllocatedCount < Selection.Count) then EdgeSaveAllocatedCount = EdgeSaveAllocatedCount + 10 : ReDim EdgeSave(EdgeSaveAllocatedCount-1) end if for EdgeIndex = 0 to Selection.Count2-1 Set EdgeSave(EdgeIndex) = Selection.Item2(EdgeIndex+1).Value next EdgeSaveCount = Selection.Count ' We propose to the user that he select an edge Status=Selection.SelectElement2(InputObjectType,"Select an edge",false) if (Status="Cancel") then Selection.Clear : Exit Sub end if ' We save the selected edge in a dedicated variable Set SelectedEdge = Selection.Item2(1).Value ' We merge the selected element with the save variables, and put the result in the selection. ' At first, we determine if the selected edge already belongs to the EdgeSave array EdgeIndex = 0 : SelectedElementBelongsToSaveVariables = False do while ((EdgeIndex < EdgeSaveCount) And (Not SelectedElementBelongsToSaveVariables)) if (EdgeSave(EdgeIndex).Name=SelectedEdge.Name) then SelectedElementBelongsToSaveVariables = True AlreadySelectedEdgeIndex = EdgeIndex end if EdgeIndex = EdgeIndex + 1 loop ' Effective merge if (Not SelectedElementBelongsToSaveVariables) then ' The selected element does not belong to the save variables. We add the save variables to the selection for EdgeIndex = 0 to EdgeSaveCount-1 Selection.Add EdgeSave(EdgeIndex) next else ' We remove the selected element from the save variables for EdgeIndex = AlreadySelectedEdgeIndex to EdgeSaveCount-2 Set EdgeSave(EdgeIndex) = EdgeSave(EdgeIndex+1) next EdgeSaveCount = EdgeSaveCount - 1 ' We clear the selection Selection.Clear ' We add the save variables to the selection for EdgeIndex = 0 to EdgeSaveCount -1 Selection.Add EdgeSave(EdgeIndex) next end if ' We ask the end user if another edge has to be selected OtherEdgeAnswer = msgbox ("do you want to select another edge?",3,"Edge Fillet Definition") if (OtherEdgeAnswer = 2) then Exit Sub if (OtherEdgeAnswer = 7) then AllEdgesHaveBeenSelected = true loop 'We create an edge fillet taking into account all the selected edges as fillet specifications if (Selection.Count > 0) then Set Fillet = ShapeFactory.AddNewEdgeFilletWithConstantRadius(Selection.Item(1).Value, 1, 5.0) Fillet.EdgePropagation = 1 for EdgeIndex = 2 to Selection.Count Fillet.AddObjectToFillet Selection.Item(EdgeIndex).Value next Part.Update : Selection.Clear : Selection.Add Fillet end if
o Func FindObject( | iObjectType) As |
Dim FoundObject As AnyObject Set FoundObject = CATIA.ActiveDocument.Selection.FindObject("CATIAPad")
o Func IndicateOrSelectElement2D( | iMessage, | |
iFilterType, | ||
iObjectSelectionBeforeCommandUsePossibility, | ||
iTooltip, | ||
iTriggeringOnMouseMove, | ||
oObjectSelected, | ||
oDocumentWindowLocation) As |
Dim Document,Selection,DrawingSheets,DrawingSheet,DrawingViews,WindowLocation(1),DrawingView,Factory2D,Radius,Circle2D Dim HardCodedPoint,Status,XCenter,YCenter,InputObjectType(0),TempCircleHasBeenCreatedAtLeastOnce,ExistingPoint Dim ObjectSelected Set Document = CATIA.ActiveDocument : Set Selection = Document.Selection : Set DrawingSheets = Document.Sheets Set DrawingSheet = DrawingSheets.ActiveSheet : Set DrawingViews = DrawingSheet.Views Set DrawingView = DrawingViews.ActiveView : Set Factory2D = DrawingView.Factory2D 'We create a point Set HardCodedPoint = Factory2D.CreatePoint(700.,400.) HardCodedPoint.ReportName = 1 : HardCodedPoint.Construction = False 'We propose to the user to click to define the circle center Status=Document.Indicate2D("click to define the circle center",WindowLocation) if (Status = "Cancel" Or Status = "Undo" Or Status = "Redo") then Exit Sub XCenter = WindowLocation(0) : YCenter = WindowLocation(1) 'We propose to the user that he specify a location into the drawing window or a point InputObjectType(0)="Point2D" Status = "MouseMove" : TempCircleHasBeenCreatedAtLeastOnce = 0 Status=Selection.IndicateOrSelectElement2D("select a point or click to locate the circle radius point", _ InputObjectType,false,false,true, _ ObjectSelected,WindowLocation) ' We loop onto mouse moves without click do while (Status = "MouseMove") if (TempCircleHasBeenCreatedAtLeastOnce) then Selection.Add Circle2D : Selection.Delete end if Radius = Sqr(((WindowLocation(0)-XCenter)*(WindowLocation(0)-XCenter))+ _ ((WindowLocation(1)-YCenter)*(WindowLocation(1)-YCenter))) Set Circle2D = Factory2D.CreateClosedCircle(XCenter,YCenter,Radius) TempCircleHasBeenCreatedAtLeastOnce = 1 Status=Selection.IndicateOrSelectElement2D("select a point or click to locate the circle radius point", _ InputObjectType,false,false,true, _ ObjectSelected,WindowLocation) loop 'We go out if necessary if (Status = "Cancel" Or Status = "Undo" Or Status = "Redo") then if (TempCircleHasBeenCreatedAtLeastOnce) then Selection.Add Circle2D : Selection.Add HardCodedPoint : Selection.Delete end if Exit Sub end if 'We determine the possible selected point coordinates if (ObjectSelected) then Set ExistingPoint = Selection.Item2(1).Value : ExistingPoint.GetCoordinates WindowLocation : Selection.Clear end if 'We clean-up the temporary circle if (TempCircleHasBeenCreatedAtLeastOnce) then Selection.Add Circle2D : Selection.Delete end if 'We create the circle Radius = Sqr(((WindowLocation(0)-XCenter)*(WindowLocation(0)-XCenter))+ _ ((WindowLocation(1)-YCenter)*(WindowLocation(1)-YCenter))) Set Circle2D = Factory2D.CreateClosedCircle(XCenter,YCenter,Radius) : Selection.Add Circle2D
o Func IndicateOrSelectElement3D( | iPlanarGeometricObject, | |
iMessage, | ||
iFilterType, | ||
iObjectSelectionBeforeCommandUsePossibility, | ||
iTooltip, | ||
iTriggeringOnMouseMove, | ||
oObjectSelected, | ||
oWindowLocation2D, | ||
oWindowLocation3D) As |
Dim Document,Part,HybridShapeFactory,Selection,Body,HybridShapePlane,PlaneReference,HardCodedPoint,Point Dim InputObjectType(0),WindowLocation2D(1),WindowLocation3D(2),TempPointHasBeenCreatedAtLeastOnce,Status Dim ObjectSelected,ExistingPoint Set Document = CATIA.ActiveDocument : Set Part = Document.Part Set HybridShapeFactory = Part.HybridShapeFactory : Set Selection = Document.Selection Set Body = Part.Bodies.Item("PartBody") : Set HybridShapePlane = Body.HybridShapes.Item("Plane.1") Set PlaneReference = Part.CreateReferenceFromObject(HybridShapePlane) 'We create a point Set HardCodedPoint = HybridShapeFactory.AddNewPointOnPlane(PlaneReference,30.,30.) Body.InsertHybridShape HardCodedPoint : Part.InWorkObject = HardCodedPoint : Part.Update 'We propose to the user that he specify a location into the part window or a point InputObjectType(0)="HybridShapePointOnPlane" Status = "MouseMove" : TempPointHasBeenCreatedAtLeastOnce = 0 : Selection.Clear Status=Selection.IndicateOrSelectElement3D(HybridShapePlane,"select a point or click to locate the point", _ InputObjectType,false,false,true, _ ObjectSelected,WindowLocation2D,WindowLocation3D) ' We loop onto mouse moves without click do while (Status = "MouseMove") if (TempPointHasBeenCreatedAtLeastOnce) then Selection.Add Point : Selection.Delete end if Set Point = HybridShapeFactory.AddNewPointOnPlane(PlaneReference,WindowLocation2D(0),WindowLocation2D(1)) Body.InsertHybridShape Point : Part.InWorkObject = Point : Part.Update TempPointHasBeenCreatedAtLeastOnce = 1 Status=Selection.IndicateOrSelectElement3D(HybridShapePlane,"select a point or click to locate the point", _ InputObjectType,false,false,true, _ ObjectSelected,WindowLocation2D,WindowLocation3D) loop 'We go out if necessary if (Status = "Cancel" Or Status = "Undo" Or Status = "Redo") then if (TempPointHasBeenCreatedAtLeastOnce) then Selection.Add Point : Selection.Add HardCodedPoint : Selection.Delete : Part.Update end if Exit Sub end if 'We determine the possible selected point coordinates if (ObjectSelected) then Set ExistingPoint = Selection.Item2(1).Value WindowLocation2D(0) = ExistingPoint.XOffset.Value : WindowLocation2D(1) = ExistingPoint.YOffset.Value Selection.Clear end if 'We clean-up the temporary point if (TempPointHasBeenCreatedAtLeastOnce) then Selection.Add Point : Selection.Delete end if 'We create the point Set Point = HybridShapeFactory.AddNewPointOnPlane(PlaneReference,WindowLocation2D(0),WindowLocation2D(1)) Body.InsertHybridShape Point : Part.InWorkObject = Point : Part.Update
o Func Item2( | iIndex) As |
o Func Item( | iIndex) As |
o Sub PasteSpecial( | iFormat) |
CATIA.ActiveDocument.Selection.PasteSpecial "CATPrtResultWithOutLink"
o Sub Paste( | ) |
CATIA.ActiveDocument.Selection.Paste()
o Sub Remove2( | iIndex) |
CATIA.ActiveDocument.Selection.Remove2(2)
o Sub Remove( | iIndex) |
o Sub Search( | iStringBSTR) |
CATIA.ActiveDocument.Selection.Search("Part.Sketcher.Color='White',all")
o Func SelectElement2( | iFilterType, | |
iMessage, | ||
iObjectSelectionBeforeCommandUsePossibility) As |
Product3 ! +- Product2 (Product2.1) ! ! ! ! +---------------------+ ! +-!Product1 (Product1.1)! ! +----------+----------+ ! ! ! +- Part1 (Part1.1) ! ! ! +- Part1 ! ! ! +- PartBody ! ! +------------------+ ! +- Pad.1 ! Selected feature ! ! ! +------------------+ ! +- Sketch.1 +- Part2 (Part2.1)it will be Product3
Note: If the scripting language is Visual Basic for Applications or Visual Basic 6 Development Studio, then,
you have to know that the use of an interactive selection method such as this one from a form (dialog box) method
requires some constraints regarding the content of an average form method.
If your macro possess a form method which calls the
SelectElement2 method, then, the content of an average form method of your macro must begin by a test, which checks that no form method is currently being executed and,
otherwise, go out of the method. This constraint enable to prevent that, during the execution of the
SelectElement2 method from a form method, when CATIA asks the end user to select a feature:
- macro module main variables: Dim AFormMethodIsBeingExecuted As Boolean - form method calling SelectElement2: Private Sub FormPossessingOneMethodCallingSelectElement2_Click() Dim InputObjectType(0), Status AFormMethodIsBeingExecuted = True InputObjectType(0)="TriDimFeatEdge" Status=Selection.SelectElement2(InputObjectType,"Select an edge",false) AFormMethodIsBeingExecuted = False End Sub - average form method: Private Sub AverageForm_Click() If (AFormMethodIsBeingExecuted) Then Exit Sub . . . ' content of the form method itself . . . End Sub
Beside the automation object names, the CATSelectionFilter value names are supported.
If the scripter:
A False value for the iObjectSelectionBeforeCommandUsePossibility parameter may be used although the selection
is not empty before entering the method. This enables that, during the selection, the selected elements remain
highlighted.
Caution: After a call to
SelectElement2 , the iObjectSelectionBeforeCommandUsePossibility parameter being set to False, the elements which were selected before the call to
SelectElement2 are not any more in the selection (unless the user selected one of them!). Consequently, such a use of the False value for the
iObjectSelectionBeforeCommandUsePossibility parameter requires the following code:
Dim Document,Part,Selection,ShapeFactory,SketchHasBeenAcquiredAtLeastOnce,EdgeHasBeenAcquiredAtLeastOnce Dim FaceHasBeenAcquiredAtLeastOnce,MonoDimEntityHasBeenAcquiredAtLeastOnce,FirstExtrudeNotFinished,FilletEdge Dim PadNotFinished,Status,SketchForPad,Pad,FilletNotFinished,Fillet,MonoDimEntityDeterminationNotFinished Dim SelectedElement,MonoDimEntity,HoleNotFinished,PadFace,Hole,InputObjectType(0),HoleLocation(2),MonoDimEntitySave Dim SketchForPadPartBody Set Document = CATIA.ActiveDocument : Set Part = Document.Part : Set Selection = Document.Selection Set ShapeFactory = Part.ShapeFactory SketchHasBeenAcquiredAtLeastOnce = False : EdgeHasBeenAcquiredAtLeastOnce = False FaceHasBeenAcquiredAtLeastOnce = False : MonoDimEntityHasBeenAcquiredAtLeastOnce = False FirstExtrudeNotFinished = True : PadNotFinished = True : ReDim SelectionAtBeginning(1) 'We save the current selection content ReDim SelectionAtBeginning(Selection.Count2) for SelectionObjectIndex = 0 to Selection.Count2-1 Set SelectionAtBeginning(SelectionObjectIndex) = Selection.Item2(1).Value next SelectionAtBeginningLength = Selection.Count2 'Feature creation do while PadNotFinished ' We propose to the user that he select a sketch InputObjectType(0)="Sketch" Status=Selection.SelectElement2(InputObjectType,"Select a sketch",true) if ((Status = "Cancel") Or (Status = "Undo")) then ' We restore the selection to its initial content Selection.Clear for SelectionObjectIndex = 0 to SelectionAtBeginningLength-1 Selection.Add SelectionAtBeginning(SelectionObjectIndex) next Exit Sub elseif (Status = "Redo" And Not SketchHasBeenAcquiredAtLeastOnce ) then ' We do nothing: Redo has no meaning in this context else if (Status <> "Redo") then Set SketchForPad = Selection.Item2(1).Value SketchHasBeenAcquiredAtLeastOnce = True ' We determine the PartBody corresponding to the Sketch Set SketchForPadPartBody = SketchForPad.Parent.Parent ' We create the Pad Set Pad = ShapeFactory.AddNewPad(SketchForPad,20.0) Pad.SecondLimit.Dimension.Value = 0.0 : Part.Update PadNotFinished = False Selection.Clear ' We create the fillet and the hole FilletNotFinished = True do while (FilletNotFinished And Not PadNotFinished) ' We propose to the user that he select an edge InputObjectType(0)="TriDimFeatEdge" Status=Selection.SelectElement2(InputObjectType,"Select an edge of the Pad",false) if (Status = "Cancel") then ' We remove the pad, restore the selection to its initial content and go out Selection.Clear : Selection.Add(Pad) : Selection.Delete Part.Update Selection.Clear for SelectionObjectIndex = 0 to SelectionAtBeginningLength-1 Selection.Add SelectionAtBeginning(SelectionObjectIndex) next Exit Sub elseif (Status = "Redo" And Not EdgeHasBeenAcquiredAtLeastOnce ) then ' We do nothing: Redo has no meaning in this context elseif (Status = "Undo") then ' We copy the sketch to the clipboard Selection.Clear : Selection.Add(SketchForPad) ' We remove the pad Selection.Clear : Selection.Add(Pad) : Selection.Delete : Part.Update ' We re-create the sketch Selection.Clear : Selection.Add(SketchForPadPartBody) : Selection.Paste() ' We store the fact that the Pad is not finished PadNotFinished = True else if (Status <> "Redo") then Set FilletEdge = Selection.Item2(1).Value EdgeHasBeenAcquiredAtLeastOnce = True ' Create the Fillet Set Fillet = ShapeFactory.AddNewSolidEdgeFilletWithConstantRadius(FilletEdge, catTangencyFilletEdgePropagation,5.0) Part.Update FilletNotFinished = False Selection.Clear ' Determine the 1-D entity MonoDimEntityDeterminationNotFinished = True do while (MonoDimEntityDeterminationNotFinished And Not FilletNotFinished) ' We propose to the user that he select 1-D entity whose geometry is rectilinear InputObjectType(0)="RectilinearMonoDim" Status=Selection.SelectElement2(InputObjectType, _ "Select a 1-D entity whose geometry is rectilinear",false) if (Status = "Cancel") then ' We remove the fillet, the pad, restore the selection to its initial content and go out Selection.Clear : Selection.Add(Fillet) : Selection.Delete Selection.Clear : Selection.Add(Pad) : Selection.Delete Part.Update Selection.Clear for SelectionObjectIndex = 0 to SelectionAtBeginningLength-1 Selection.Add SelectionAtBeginning(SelectionObjectIndex) next Exit Sub elseif (Status = "Redo" And Not MonoDimEntityHasBeenAcquiredAtLeastOnce ) then ' We do nothing: Redo has no meaning in this context elseif (Status = "Undo") then ' We remove the fillet Selection.Clear : Selection.Add(Fillet) : Selection.Delete Part.Update FilletNotFinished = True else if (Status = "Redo") then Selection.Clear : Selection.Add(MonoDimEntity) else Set SelectedElement = Selection.Item2(1) Set MonoDimEntity = SelectedElement.Value end if MonoDimEntityHasBeenAcquiredAtLeastOnce = True MonoDimEntityDeterminationNotFinished = False ' Create the Hole HoleNotFinished = True do while (HoleNotFinished And Not MonoDimEntityDeterminationNotFinished) ' We save the selection content in save variables. ' This corresponds to the fact that: ' - we want that, during the following call to SelectElement2, the 1-D entity previously ' selected remain highlighted ' - this is done using the False value for the iObjectSelectionBeforeCommandUsePossibility ' parameter, the selection containing the 1-D entity. It requires that the selection ' content be saved Set MonoDimEntitySave = Selection.Item2(1).Value ' We propose to the user that he select a face InputObjectType(0)="Face" Status=Selection.SelectElement2(InputObjectType, _ "Select a face perpendicular to the 1-D entity",false) if (Status = "Cancel") then ' We remove the fillet, the pad, restore the selection to its initial content and go out Selection.Clear : Selection.Add(Fillet) : Selection.Delete Selection.Clear : Selection.Add(Pad) : Selection.Delete Selection.Clear for SelectionObjectIndex = 0 to SelectionAtBeginningLength-1 Selection.Add SelectionAtBeginning(SelectionObjectIndex) next Part.Update Exit Sub elseif (Status = "Redo" And Not FaceHasBeenAcquiredAtLeastOnce ) then ' We do nothing: Redo has no meaning in this context elseif (Status = "Undo") then Selection.Clear ' The 1-D entity must be re-selected MonoDimEntityDeterminationNotFinished = True else if (Status <> "Redo") then Set SelectedElement = Selection.Item2(1) Set PadFace = SelectedElement.Value SelectedElement.GetCoordinates HoleLocation ' We merge the selected element with the save variables, and put the result in the selection Selection.Add MonoDimEntitySave end if FaceHasBeenAcquiredAtLeastOnce = True ' We create the Hole Set Hole = Part.ShapeFactory.AddNewHoleFromPoint(HoleLocation(0),HoleLocation(1),HoleLocation(2),PadFace,10.0) Hole.ThreadingMode = 1 : Hole.ThreadSide = 0 : Hole.Diameter.Value = 5.0 Hole.SetDirection FilletEdge Part.Update HoleNotFinished = False ' We clear the selection Selection.Clear end if loop end if loop end if loop end if loop
o Func SelectElement3( | iFilterType, | |
iMessage, | ||
iObjectSelectionBeforeCommandUsePossibility, | ||
iMultiSelectionMode, | ||
iTooltip) As |
Dim Document,Part,Selection,HybridShapeFactory,HybridBodies,HybridBody,OriginElements,Plane,PlaneReference,Status Dim InputObjectType(0),PointIndex,PointReference,HybridShapeSymmetry Set Document = CATIA.ActiveDocument : Set Part = Document.Part : Set Selection = Document.Selection Set HybridShapeFactory = Part.HybridShapeFactory Set Bodies = Part.Bodies Set Body = Bodies.Item("PartBody") Set OriginElements = Part.OriginElements Set Plane = OriginElements.PlaneZX Set PlaneReference = Part.CreateReferenceFromObject(Plane) 'We propose to the user that he select several points, drawing a trap InputObjectType(0)="Point" Status=Selection.SelectElement3(InputObjectType,"Select points", _ true,CATMultiSelTriggWhenSelPerf,false) if (Status = "Cancel") then Exit Sub For PointIndex = 1 to Selection.Count2 Set PointReference = Part.CreateReferenceFromObject(Selection.Item2(PointIndex).Value) Set HybridShapeSymmetry = HybridShapeFactory.AddNewSymmetry(PointReference,PlaneReference) HybridShapeSymmetry.VolumeResult = False Body.InsertHybridShape HybridShapeSymmetry Part.InWorkObject = HybridShapeSymmetry Part.Update next Selection.Clear
'We create a drawing Set Documents = CATIA.Documents : Set Document = Documents.Add("Drawing") : Document.Standard = catISO Set DrawingSheets = Document.Sheets : Set DrawingSheet = DrawingSheets.Item("Sheet.1") DrawingSheet.PaperSize = catPaperA0 : DrawingSheet.Scale = 1.000000 : DrawingSheet.Orientation = catPaperLandscape Set DrawingViews = DrawingSheet.Views : Set DrawingView = DrawingViews.ActiveView Set Factory2D = DrawingView.Factory2D : Set Selection = Document.Selection : Dim Coordinates(2) ReDim InputObjectType(0) : Dim SelectedPoint(3) : SelectedPointCount = 0 'We create a horizontal line with a zero ordinate Set LineLeftExtremity = Factory2D.CreatePoint(-100.0, 0.0) : LineLeftExtremity.ReportName = 3 Set LineRightExtremity = Factory2D.CreatePoint(100.0, 0.0) : LineRightExtremity.ReportName = 4 Set Line2D = Factory2D.CreateLine(-100.0, 0.0, 100.0, 0.0) : Line2D.ReportName = 5 Line2D.StartPoint = LineLeftExtremity : Line2D.EndPoint = LineRightExtremity 'We create three points Set Point2D1 = Factory2D.CreatePoint(-50.0, 50.0) : Point2D1.ReportName = 6 : Point2D1.Construction = False Set Point2D2 = Factory2D.CreatePoint(0.0, 70.0) : Point2D2.ReportName = 7 : Point2D1.Construction = False Set Point2D3 = Factory2D.CreatePoint(50.0, 50.0) : Point2D3.ReportName = 8 : Point2D3.Construction = False 'We mention to the user that he will select the set of elements to be symmetrized msgbox "This tool will enable you to learn how to use the Symmetry command." & Chr(13) & Chr(13) & _ "Suppose you selected the Symmetry command." & Chr(13) & _ "You will first select several points to be symmetrized" 'We propose to the user that he select several points InputObjectType(0)="Point2D" Status=Selection.SelectElement3(InputObjectType,"Select the set of elements to be symmetrized", _ true,CATMultiSelTriggWhenUserValidatesSelection,false) if (Status = "Cancel") then Exit Sub 'We add the selected points to SelectedPoint for PointIndex = 0 to Selection.Count2-1 Set SelectedPoint(PointIndex) = Selection.Item2(PointIndex+1).Value : SelectedPointCount = SelectedPointCount+1 next 'We mention to the user that he will select the axis from which the elements will remain equidistant msgbox "You will then select the line from which the elements will remain equidistant" 'We propose to the user that he select the line InputObjectType(0)="Line2D" Status=Selection.SelectElement2(InputObjectType, _ "Select the line or axis from which the elements will remain equidistant", false) if (Status = "Cancel") then Exit Sub 'We move the selected points by symmetry according to the selected line for PointIndex = 0 to SelectedPointCount-1 Set CurrentPoint2D = SelectedPoint(PointIndex) CurrentPoint2D.GetCoordinates Coordinates CurrentPoint2D.SetData Coordinates(0), -Coordinates(1) next Selection.Clear 'We mention to the user that the points have successfully been moved msgbox "The points have successfully been moved."
o Func SelectElement4( | iFilterType, | |
iActiveDocumentMessage, | ||
iNonActiveDocumentMessage, | ||
iTooltip, | ||
oDocument) As |
Dim DrawingSelection,DrawingSheets,DrawingSheet,DrawingViews,DrawingFrontView : ReDim DrawingSelectionAtBeginning(1) Dim Status,InputObjectType(0),Plane,Drawing,DrawingViewGenerativeBehavior,V1(2),V2(2),PartDocument Set Drawing = CATIA.ActiveDocument : Set DrawingSelection = Drawing.Selection : Set DrawingSheets = Drawing.Sheets Set DrawingSheet = DrawingSheets.ActiveSheet 'We save the current selection content ReDim DrawingSelectionAtBeginning(DrawingSelection.Count2) for SelectionObjectIndex = 0 to DrawingSelection.Count2-1 Set DrawingSelectionAtBeginning(SelectionObjectIndex) = DrawingSelection.Item2(1).Value next SelectionAtBeginningLength = DrawingSelection.Count2 'Feature creation InputObjectType(0)="BiDimInfinite" Status=DrawingSelection.SelectElement4(InputObjectType,"Select a 2-D topological entity in a 3-D geometry", _ "Select a 2-D topological entity",false,PartDocument) if ((Status = "Cancel") Or (Status = "Undo") Or (Status = "Redo")) then ' We restore the selection to its initial content PartDocument.Selection.Clear for SelectionObjectIndex = 0 to SelectionAtBeginningLength-1 DrawingSelection.Add DrawingSelectionAtBeginning(SelectionObjectIndex) next Exit Sub else Set BiDimFeature = PartDocument.Selection.Item2(1).Value BiDimFeatureType = TypeName(BiDimFeature) if ((BiDimFeatureType="Plane") Or (BiDimFeatureType="PlanarFace")) then BiDimFeature.GetFirstAxis V1 BiDimFeature.GetSecondAxis V2 else Exit Sub end if ' We create a view called "Front View" in the current sheet, using Plane as projection plane, and whose origin ' coordinates are 300,150 Set DrawingFrontView = DrawingSheet.Views.Add("Front View") Set DrawingViewGenerativeBehavior = DrawingFrontView.GenerativeBehavior DrawingViewGenerativeBehavior.Document = PartDocument DrawingViewGenerativeBehavior.DefineFrontView V1(0), V1(1), V1(2), V2(0), V2(1), V2(2) DrawingFrontView.x = 300 DrawingFrontView.y = 150 DrawingViewGenerativeBehavior.Update ' We clear the PartDocument Selection object PartDocument.Selection.Clear end if
Copyright © 2003, Dassault Systèmes. All rights reserved.