I have an ilogic bend that works well
i would like to use this is in an assembly and be able to alter the parameter when inserted and have a new part created ( file name based on size parameters , 200_45 ( 200 dia 45 deg ) and saved in the workspace
is this possible and can anyone help pls
keith
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
I have done something similar in the past.
My go was :
Create the standart part with all the parameters, and create an user interface in that part to control those parameters.
Then on the assembly level, I created a iLogic rule :
- Insert the standard part
- Open the part, open the user form to configure the part.
- When I'm done configuring, close the user form and "save as" the part
- Close the part file.
- Replace the standard part in the assembly with the newly genereted part.
Done.
Regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"laurent
thank you for your answer
i have something sort of working only i wish to refine it
at the moment I insert the std part and make it active and run a form to assign the parameters then save it as a new file name
(Not all my own code )
I would like to have the form run automatically on insert and the file name generated from the "dia" and "angle" parameters
This one might be helpful (not sure) :
For opening a form using iLogic :
iLogicForm.Show("MyForm")
For the name, you could maybe declare few text variables :
Dim sString1 As String = MyUserParameter1 Dim sString2 As String = MyUserParameter2 Dim sNewPartName As String = sString1 & sString2 & ".ipt"
Regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Try this iLogic code 🙂 Run it from within your assembly. Make sure the assembly is saved and make sure the path to your template file is correct. Let me know how it works for you 🙂
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oPath As String = ThisDoc.Path If oPath = "" MsgBox("Save assembly first!") Exit Sub End If Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200") Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90") If System.IO.File.Exists(oPath & "\" & oDia & "_" & oAngle & ".ipt") Then ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute Else '-------------------YOU MUST PUT YOUR PATH TO THE TEMPLATE .ipt HERE:----------------------- Dim oTemplate As String = "C:\Users\hfljf\Desktop\ILOGIC TEST.ipt" 'Path to the ipt '-------------------------------------------------------------------------------------------- Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia pDoc.ComponentDefinition.Parameters.Item("ANGLE").Expression = oAngle pDoc.Update pDoc.SaveAs(oPath & "\" & oDia & "_" & oAngle & ".ipt", False) pDoc.Close ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute End If
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
JHOEL
that works well thank you
is there any way that the bend radius can be set in the same way I have tried but it doesnt alter the part
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oPath As String = ThisDoc.Path If oPath = "" MessageBox.Show("Message","Title", MessageBoxButtons.OK) End If Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200") Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90") Dim oBendRadius As String = InputBox("BendRadius:", "BendRadius", "1") If System.IO.File.Exists(oPath & "\" & oDia & "_" & oAngle & ".ipt" & oBendRadius & ".ipt") Then ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & ".ipt" & oBendRadius & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute Else Dim oTemplate As String = "\\DNSERVER01\RedirectedFolders\KeithChallinor\My Documents\Inventor\test\Part1.ipt" Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia pDoc.ComponentDefinition.Parameters.Item("ANGLE").Expression = oAngle pDoc.ComponentDefinition.Parameters.Item("BendRadius").Expression = oBendRadius pDoc.Update pDoc.SaveAs(oPath & "\" & oDia & "_" & oAngle & "_" & oBendRadius & ".ipt", False) pDoc.Close ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & "_" & oBendRadius & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute End If
I'm glad it works for you! Seems like the thing is that you must have the template document closed before running the code 🙂
This works for me, try it! The name of the parameter for bend radius is "BEND_RAD" in your template part, thats basically everything I've changed. I also added a UserInterfaceManager.DoEvents to give inventor time to process its queue and an update command at the end of the code.
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oPath As String = ThisDoc.Path If oPath = "" MessageBox.Show("Message","Title", MessageBoxButtons.OK) End If Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200") Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90") Dim oBendRadius As String = InputBox("BendRadius:", "BendRadius", "1") If System.IO.File.Exists(oPath & "\" & oDia & "_" & oAngle & ".ipt" & oBendRadius & ".ipt") Then ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & ".ipt" & oBendRadius & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute Else Dim oTemplate As String = "\\DNSERVER01\RedirectedFolders\KeithChallinor\My Documents\Inventor\test\Part1.ipt" Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia pDoc.ComponentDefinition.Parameters.Item("ANGLE").Expression = oAngle pDoc.ComponentDefinition.Parameters.Item("BEND_RAD").Expression = oBendRadius pDoc.Update ThisApplication.UserInterfaceManager.DoEvents pDoc.SaveAs(oPath & "\" & oDia & "_" & oAngle & "_" & oBendRadius & ".ipt", False) pDoc.Close ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oDia & "_" & oAngle & "_" & oBendRadius & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute End If oAsm.Update
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
I uploaded this screencast to post here to show how the code is meant to be used. You figured it out before I had the chance to post it, so I'll just go ahead and post it anyway for someone that may find this thread in the future. This was before i added the bendradius parameter though 🙂
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
many thanks for this i have it working now with more and really appreciate your help 🙂
thickness,dia,angle,bendradius
if i wish to have a code entered at the beginning as text would that also be a string or would it be different
Dim oCode As ????? = InputBox("Code:", "Code", "W")
Dim oThickness As String = InputBox("Thickness:","Thickness", "2" Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200") Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90")
I'm glad it works for you! 🙂
I don't really know what you want to use the variable oCode for, but the String type is text (a string of characters) , and the InputBox returns a value of type string - so I'd say yes, it should be a string
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
all working perfectly now thank you
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPath As String = ThisDoc.Path
If oPath = ""
MessageBox.Show("Message", "Title", MessageBoxButtons.OK)
End If
Dim oCode As String = InputBox ("Code:", "Code","W")
Dim oThickness As String = InputBox("Thickness:", "Thickness", "2")
Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200")
Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90")
Dim oBendRadius As String = InputBox("BendRadius:", "BendRadius", "1")
Dim oFlange As String = InputBox ("Flange:", "Flange","fb")
If System.IO.File.Exists(oPath & "\" & oCode & "_" & oThickness & "_" & oDia & "_" & oAngle & "_" & oBendRadius & "_" & oFlange & ".ipt") Then
ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oCode & "_" & oThickness & "_" & oDia & "_" & oAngle & "_" & oBendRadius & "_" & oFlange & ".ipt")
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
Else
Dim oTemplate As String = "\\DNSERVER01\RedirectedFolders\KeithChallinor\My Documents\Inventor\test\Part1.ipt"
Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False)
pDoc.ComponentDefinition.Parameters.Item("Thickness").Expression = oThickness
pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia
pDoc.ComponentDefinition.Parameters.Item("ANGLE").Expression = oAngle
pDoc.ComponentDefinition.Parameters.Item("BendRadius").Expression = oBendRadius
pDoc.Update
ThisApplication.UserInterfaceManager.DoEvents
pDoc.SaveAs(oPath & "\" & oCode & "_" & oThickness & "_" & oDia & "_" & oAngle & "_" & oBendRadius & "_" & oFlange & ".ipt", False)
pDoc.Close
ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\" & oCode & "_" & oThickness & "_" & oDia & "_" & oAngle & "_" & oBendRadius & "_" & oFlange & ".ipt")
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
End If
oAsm.Update
i have noticed that when the same part is called up the code errors as the part already exists
is there a way to cancel the create , and have inventor insert the part from the browser if it already exists in the assembly
TIA
keith
I see the error now! The code is meant to check if the part already exists, and if it does - place that part. But I made a type of sorts. The filename it checks for contains two ".ipt" so it's not a valid filename. See line below:
If System.IO.File.Exists(oPath & "\" & oDia & "_" & oAngle & ".ipt" & oBendRadius & ".ipt") Then
that file will of course never exist.
I rewrote the code a bit now so that the filename is stored in a variable that's reused throughout the code. It minimazes the risk for typos... See code below, it's tested and it works 🙂
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oPath As String = ThisDoc.Path If oPath = "" MessageBox.Show("You must save the assembly first", "iam not saved", MessageBoxButtons.OK) Exit Sub End If Dim oDia As String = InputBox("Diameter:", "Pipe diameter", "200") Dim oAngle As String = InputBox("Angle:", "Pipe bend angle", "90") Dim oBendRadius As String = InputBox("BendRadius:", "BendRadius", "1") Dim cmdMgr As CommandManager = ThisApplication.CommandManager Dim oFileName As String = oPath & "\" & oDia & "_" & oAngle & "_" & oBendRadius & ".ipt" If System.IO.File.Exists(oFileName) Then cmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFileName) cmdMgr.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute Else Dim oTemplate As String = "\\DNSERVER01\RedirectedFolders\KeithChallinor\My Documents\Inventor\test\Part1.ipt" Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia pDoc.ComponentDefinition.Parameters.Item("ANGLE").Expression = oAngle pDoc.ComponentDefinition.Parameters.Item("BEND_RAD").Expression = oBendRadius pDoc.Update ThisApplication.UserInterfaceManager.DoEvents pDoc.SaveAs(oFileName, False) pDoc.Close cmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFileName) cmdMgr.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute End If oAsm.Update
Just add the extra parameters again... This version only handles Diameter, angle and bendradius 🙂
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Can't find what you're looking for? Ask the community or share your knowledge.