Ok I am trying to program an iLogic code that does the following
Prompts user to select Square or Round Pin
Then Askes the user for the sizes
Square Pin
Length
Width
Height
Round Pin
Diameter
Height
Where Height is the extrude length
What ever done is created a 2d Sketch with a square and circle in it and it extruded it Now if the user selects Square pin
By Default Diameter will be set to 0in
and
Length = 1
Width = 1
The problem Im having is that if the user goes back and decideds it needs to be a round pin the sketch changes but the extruded feature errors out because the profile changed
Does anyone know how I can update the profile of the extrusion? Ive tried this code but the problem Im getting is that once the extrusion is deleted it does rename the new extrusion "extrude1" which means should the user want to change the pin from square to round multiple times the code will only find ExtrudeFeatures("Extrude1") Once and error our should the user try to change it again. And no creating 2 different extrusions and just supressing 1 depending on the selection it out of the question. Thank you
Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition Call oCompDef.Features.ExtrudeFeatures("Extrude1").Delete(True, True) Dim oSketch As PlanarSketch oSketch = oCompDef.Sketches("Sketch1") Dim oProfile As Profile oProfile = oSketch.Profiles.AddForSolid oDistance = Height oJoinOrCut = kJoinOperation oDirection = kSymmetricExtentDirection Dim oExtrude As ExtrudeFeature oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent( _ oProfile, oDistance, oDirection, oJoinOrCut)
If your sketch always has a rectangle and a circle drawn, this should work for you :
'get user input
extrudeshape = InputBox("Circle or Square?", "Circle or Square?", "Square")
' Get the active part document
Dim oPartDoc As PartDocument = ThisDoc.Document
' Get comp definition
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
' Get the existing sketch with square and circle
Dim oSketch As PlanarSketch = oCompDef.Sketches.Item("Sketch1")
' get transient geometry object.
Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry
' get reference to existing feature
Dim oExtrude As ExtrudeFeature = Feature.InventorFeature("Extrusion2")
' create an object collection
Dim oPathSegments As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'sketch lines (for rectangle), sketch circles (for circle)
Dim oLines As SketchLine
Dim oCircles As SketchCircle
'based on the user input, get :
' - All of the sketch LINES in the sketch
'OR
' - All of the sketch CIRCLES in the sketch
' - NOTE, you need to update the document when changing to the circle from 0 diameter.
If extrudeshape = "Square" Then
'get the rectangle
For Each oLines In oSketch.SketchLines
oPathSegments.Add(oLines)
Next
Parameter("dia") = 0
Else If extrudeshape = "Circle" Then
'get the circle
Parameter("dia") = 50
InventorVb.DocumentUpdate()
For Each oCircles In oSketch.SketchCircles
oPathSegments.Add(oCircles)
Next
End If
'create the new profile - could be a circle or square
oProfile = oSketch.Profiles.AddForSolid(False, oPathSegments)
' give the extrusion the new profile
oExtrude.Profile = oProfile
The extrusion profile will change dependant on the users answer.
(You may need to tidy it up to get it working for your situation)
Cheers,
Tom
No not exactly here is some more code I used a square and circle as an example in the first post because those were 2 of the 5 different profiles all in "Sketch1" basically if the user selects plate the code needs to set intial values for the 2d sketch of the plate and set all the other dimensions for the other profiles in Sketch1 to 0 (zero). The below code does this perfectly the problem Im having is that If I change from Plate to Pin the extruded profile doesnt update it errors out but the sketch changes from a square to a circle, the other problem Im having is because I set the parameters to an initial number if I try to change them in my Form (Example the plates initiall values 1 x 2 x 3, and I need to change it to 1 x 6 x 12 but when I type in the new number in the form for that parameter (which drives the dimension on the sketch) it just reverts back to the intial value) hope this makes some sense
MultiValue.SetList("ModelType", "Pin", "Plate", "Angle", "Round Tube", "Square Tube")
MultiValue.UpdateAfterChange = (True)
MultiValue.SetValueOptions(True)
If ModelType = "Angle" Then
'Angle Parameters
LLeg = 4
SLeg = 2
AngWt = .25
'Plate Parameters
PWidth = 0
PHeight = 0
'Pin Parameters
PDia = 0
'Round Tube Parameters
ODia = 0
RndWt = 0
'Square Tube Parameters
SQWidth = 0
SQHeight = 0
SQTWt = 0
'Common Parameters (Extrusion)
'Length = 2
ElseIf ModelType = "Plate" Then
'Angle Parameters
LLeg = 0
SLeg = 0
AngWt = 0
'Plate Parameters
PWidth = 2
PHeight = 1
'Pin Parameters
PDia = 0
'Round Tube Parameters
ODia = 0
RndWt = 0
'Square Tube Parameters
SQWidth = 0
SQHeight = 0
SQTWt = 0
'Common Parameters (Extrusion)
Length = 3
ElseIf ModelType = "Pin" Then
'Angle Parameters
LLeg = 0
SLeg = 0
AngWt = 0
'Plate Parameters
PWidth = 0
PHeight = 0
'Pin Parameters
PDia = .5
'Round Tube Parameters
ODia = 0
RndWt = 0
'Square Tube Parameters
SQWidth = 0
SQHeight = 0
SQTWt = 0
'Common Parameters (Extrusion)
Length = 2
ElseIf ModelType = "Round Tube" Then
'Angle Parameters
LLeg = 0
SLeg = 0
AngWt = 0
'Plate Parameters
PWidth = 0
PHeight = 0
'Pin Parameters
PDia = 0
'Round Tube Parameters
ODia = 2
RndWt = .125
'Square Tube Parameters
SQWidth = 0
SQHeight = 0
SQTWt = 0
'Common Parameters (Extrusion)
'Length = 2
ElseIf ModelType = "Square Tube" Then
'Angle Parameters
LLeg = 0
SLeg = 0
AngWt = 0
'Plate Parameters
PWidth = 0
PHeight = 0
'Pin Parameters
PDia = 0
'Round Tube Parameters
ODia = 0
RndWt = 0
'Square Tube Parameters
SQWidth = 2
SQHeight = 2
SQTWt = 0.095
'Common Parameters (Extrusion)
'Length = 2
End If
Hope someone can make sense of this and thanks for the help so far
Happy New Year!
If you are still having issues with this then the best would be if you could create a new document from scratch that is as simple as possible but enough to reproduce the issue.
Then also provide the exact steps we need to follow to reproduce the problem.
Thank you,