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!

parameter + Formula + relations

Status
Not open for further replies.

DomKum

Automotive
Nov 27, 2005
23
Hi Experts
May I request for help to correct this issue.
Trying to create a sphere with exiting points. Requirement is to create a sphere with parameter. I followed your youtube video but not able to fix the problem.
Not able to create formula to connect to radius of sphere.

Language=”VBSCRIPT”
‘ * * * * * * * * * * * * *
‘This MACRO is to create a parametric sphere with diameter as input
‘points in GS
‘ * * * * * * * * * * * * * – – – – – – – – – – – * * * * * * *

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set parameters1 = part1.Parameters

Set hybridBodies1 = part1.HybridBodies

‘Set hybridShapes1 = hybridBody1.HybridShapes

Set axisSystems1 = part1.AxisSystems

msgbox (“Select the geometrical set with I/P points for creating Sphere”)

Dim oSelection ‘as Selection
Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = “HybridBody”
Status = oSelection.SelectElement2(InputObjectType, “Select Geometrical set.”, True)

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

Set parameters1 = part1.Parameters

Dim length1 ‘As Dimension
Set length1 = parameters1.CreateDimension(“”, “LENGTH”, 0.000000)
length1.Rename “SPDia”
length1.Value = 25.000000

‘Spheredia=Inputbox(“Enter Diameter of sphere to be created”)

Dim iCount

Dim i ‘As Integer

oSelection.Search “CATGmoSearch.Point,sel”

iCount = oSelection.Count

For i = 1 to iCount

Set hybridShapePointOnSurface1 = oSelection.Item(i).Value

Dim reference1 ‘As reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim relations1 ‘As Relations
Set relations1 = part1.Relations

Dim formula1 ‘As Formula
Set formula1 = relations1.CreateFormula(“Formula.2”, “”, length1, SPDia)

formula1.Rename “Formula.2”

Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, Nothing, SPDia, -45.000000, 45.000000, 0.000000, 180.000000)

hybridShapeSphere1.Limitation = 1

hybridBody1.AppendHybridShape hybridShapeSphere1

part1.InWorkObject = hybridShapeSphere1

hybridShapeSphere1.name = “Shpere for-” & oSelection.Item(i).Value.name

‘part1.Update

NEXT

part1.Update

msgbox (“Total number of sphere created -” & iCount)

End Sub
 
Replies continue below

Recommended for you

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set hybridBodies1 = part1.HybridBodies
Set axisSystems1 = part1.AxisSystems

MsgBox ("Select the geometrical set with I/P points for creating Sphere")

Dim oSelection 'as Selection
Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject

Set parameters1 = part1.Parameters

Dim length1 'As Dimension
Set length1 = parameters1.CreateDimension("", "LENGTH", 0)
length1.Rename "SPDia"
length1.Value = 25

'Spheredia=Inputbox("Enter Diameter of sphere to be created")

Dim iCount

Dim i 'As Integer

oSelection.Search "CATGmoSearch.Point, sel"

iCount = oSelection.Count

For i = 1 To iCount

Set hybridShapePointOnSurface1 = oSelection.item(i).Value

Dim reference1 'As reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim relations1 'As Relations
Set relations1 = part1.Relations
Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, Nothing, length1.Value, -45#, 45#, 0#, 180#)
hybridShapeSphere1.Limitation = 1

Dim myradius
Set myradius = hybridShapeSphere1.Radius

Dim formula1 'As Formula
Set formula1 = relations1.CreateFormula("Formula.2", "", myradius, SPDia)
formula1.Rename "Formula.2"

hybridBody1.AppendHybridShape hybridShapeSphere1
part1.InWorkObject = hybridShapeSphere1
hybridShapeSphere1.name = "Shpere for-" & oSelection.item(i).Value.name

Next

part1.Update

MsgBox ("Total number of sphere created -" & iCount)

End Sub

regards,
LWolf
 
two changes: in Set HybridShapeSphere1 you need a value of the radius...
and then I added myradius, which takes the sphereradius as its reference...

regards,
LWolf
 
disregard my inputs... just realised you want to have the parameter controlling your sphere...

regards,
LWolf
 
ok, sorry for all the spam, delete doesn't work for me today...
here is my last input, (i promise)
here is the working code... I changed the formula to go for the parameter.name ( Set formula1 = relations1.CreateFormula("Formula.2", "", myradius, parameters1.item("SPDia").name))

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set hybridBodies1 = part1.HybridBodies
Set axisSystems1 = part1.AxisSystems

MsgBox ("Select the geometrical set with I/P points for creating Sphere")

Dim oSelection 'as Selection
Dim InputObjectType(0)

Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
InputObjectType(0) = "HybridBody"
Status = oSelection.SelectElement2(InputObjectType, "Select Geometrical set.", True)

Set hybridBody1 = hybridBodies1.Add()
Set hybridBody1 = CATIA.ActiveDocument.Part.InWorkObject
Set parameters1 = part1.Parameters
Dim length1 'As Dimension
Set length1 = parameters1.CreateDimension("MM", "LENGTH", 25)
length1.Rename "SPDia"
'Spheredia=Inputbox("Enter Diameter of sphere to be created")
Dim iCount
Dim i 'As Integer
oSelection.Search "CATGmoSearch.Point, sel"

iCount = oSelection.Count

For i = 1 To iCount

Set hybridShapePointOnSurface1 = oSelection.item(i).Value

Dim reference1 'As reference
Set reference1 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim relations1 'As Relations
Set relations1 = part1.Relations
Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, Nothing, length1.Value, -45#, 45#, 0#, 180#)
hybridShapeSphere1.Limitation = 1

Dim myradius
Set myradius = hybridShapeSphere1.Radius
Dim formula1 'As Formula
Set formula1 = relations1.CreateFormula("Formula.2", "", myradius, parameters1.item("SPDia").name)
'formula1.Rename "Formula.2"

hybridBody1.AppendHybridShape hybridShapeSphere1
part1.InWorkObject = hybridShapeSphere1
hybridShapeSphere1.name = "Shpere for-" & oSelection.item(i).Value.name
Next

part1.Update

MsgBox ("Total number of sphere created -" & iCount)

End Sub


regards,
LWolf
 
Thank you LWolf for your suggestion & guidance.
Its working now.
 
Hi LWolf,

I just forgot to mention that with the code as below - I mean # included in the script, Macro is showing an error while I try to exeucte.
However replacing # with -45.000/etc its working fine.
Set hybridShapeSphere1 = hybridShapeFactory1.AddNewSphere(reference1, Nothing, length1.Value, -45#, 45#, 0#, 180#)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor