Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Change Extrude Profile *Help*

3 REPLIES 3
Reply
Message 1 of 4
ComputerGuru666
1134 Views, 3 Replies

iLogic Change Extrude Profile *Help*

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)

 

 

Computer Specs:
Windows 7 (64 Bit) Pro. SP1, Inventor 2014 Pro, 3D Connexion SpaceNavigator (Driver 3.15.2)
Motherboard: ASUS Rampage IV Extreme x79 Socket 2011
Processor: Intel Core i7 Six Core Sandy Bridge-E 3.2GHz OCed to 4.7GHz (Under Water)
RAM: G.Skill Ripjaw Z-Series 32 gig quad channel of RAM 1800MHz OCed to 2133MHz
Video Card: 2x Nvidia Geforce GTX 770 (Running Six (6) Monitors)
Monitors: [Primary = 2x 24in HD WS][Secondary = 2x 22in HD WS][Tertiary = 2x 19in FS]
Primary Hard Drive: OCZ Vertex IV 256 GB Solid State Drive
Secondary Hard Drive: OCZ Vertex III 120 GB Solid State Drive
3 REPLIES 3
Message 2 of 4

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

Message 3 of 4

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

 

Computer Specs:
Windows 7 (64 Bit) Pro. SP1, Inventor 2014 Pro, 3D Connexion SpaceNavigator (Driver 3.15.2)
Motherboard: ASUS Rampage IV Extreme x79 Socket 2011
Processor: Intel Core i7 Six Core Sandy Bridge-E 3.2GHz OCed to 4.7GHz (Under Water)
RAM: G.Skill Ripjaw Z-Series 32 gig quad channel of RAM 1800MHz OCed to 2133MHz
Video Card: 2x Nvidia Geforce GTX 770 (Running Six (6) Monitors)
Monitors: [Primary = 2x 24in HD WS][Secondary = 2x 22in HD WS][Tertiary = 2x 19in FS]
Primary Hard Drive: OCZ Vertex IV 256 GB Solid State Drive
Secondary Hard Drive: OCZ Vertex III 120 GB Solid State Drive
Message 4 of 4
adam.nagy
in reply to: ComputerGuru666

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,



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report