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!

CATIA V5 Macro - Line Normal From Multi-Section Surface

Status
Not open for further replies.

evereux

Aerospace
Feb 17, 2013
14
FR
I've created my first useful macro which creates a line normal from a multi-section generated surface using a point that has been created along a curve. You need to select the items first with the surface being your first selection. Also, you should have a geometric set called Vectors.

I share this as I struggled to find something that worked, that I understood and therefore modify for my own requirements. Hopefully the below will help point you in the right direction.

If you don't have the same surface or point types as described above check the V5Automation.chm (in your CATIA installation directory) document and search for Hybrid Shapes Automation Objects. You can then swap out hybridShapeLoft and hybridShapePointOnCurve with your specifc hybrid shape type.

Code:
Sub CATMain()

	Dim myDocument
	Set myDocument = CATIA.ActiveDocument
	
	Dim i As Integer
	
	Dim mySelection As Selection
	Set mySelection = myDocument.Selection

	Dim ThePart As Part
	Set ThePart = myDocument.Part

	Dim hybridShapeFactory1 As Factory
	Set hybridShapeFactory1 = ThePart.HybridShapeFactory
	
	Dim hybridBodies1 As HybridBodies
	Set hybridBodies1 = ThePart.HybridBodies

	Dim SelectedElement1 As SelectedElement
	Set SelectedElement1 = mySelection.Item(1)

	Dim hybridShapeLoft1 As hybridShapeLoft
	Set hybridShapeLoft1 = SelectedElement1.Value

	Dim reference1 As Reference
	Set reference1 = ThePart.CreateReferenceFromObject(hybridShapeLoft1)
	
	For i = 2 To myselection.Count
		
		Dim Select2 As SelectedElement
		Set SelectedElement2 = mySelection.Item(i)

		Dim hybridShapePointOnCurve1 as hybridShapePointOnCurve
		Set hybridShapePointOnCurve1 = SelectedElement2.Value

		Dim reference2 As Reference
		Set reference2 = ThePart.CreateReferenceFromObject(hybridShapePointOnCurve1)
		
		Dim hybridShapeLineNormal1 As hybridShapeLineNormal
		Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 15, -15, False)
	
		Set hybridBody1 = hybridBodies1.Item("Vectors")

		hybridBody1.AppendHybridShape hybridShapeLineNormal1
		ThePart.InWorkObject = hybridShapeLineNormal1
		
		ThePart.Update

	Next 'i

End Sub

As always, if there are any tips on how I could improve things please do let me know.

What's a good way of avoiding being tied down to surface and point types within a macro? IMO the nature of the task means a good script wouldn't care what type of surface or point you have and would be more flexible.
 
Replies continue below

Recommended for you

What about using "Select Case" ? Bellow an example - each case can be a certain type of input - points or whatever...or you can evaluate before what kind of points type they are....another function....you are on the good way.

Dim Input
Input = InputBox ("Please write a number between 0 and 2", 0)

Select Case Input
Case "0"
MsgBox ("Input Number = 0")
Case "1", "2"
MsgBox ("Input Number > 0")
Case Else
MsgBox ("No input Number ")
End Select


Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor