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: 

LOGIC

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Keith.Challinor3761
1061 Views, 15 Replies

LOGIC

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 

Labels (1)
15 REPLIES 15
Message 2 of 16

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"

@LinkedIn     @JohnCockerill

Message 3 of 16

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

 

Message 4 of 16

This one might be helpful (not sure) :

 

https://forums.autodesk.com/t5/inventor-forum/triggering-a-part-rule-to-run-when-placed-in-an-assemb...

 

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"

@LinkedIn     @JohnCockerill

Message 5 of 16

Hi @Keith.Challinor3761 

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
Message 6 of 16

Hi

Thanks for this but I am having trouble debugging it
Sorry

Keith

[cid:image001.png@01D6A636.932B6DB0]
Message 7 of 16

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 
Message 8 of 16

Hi @Keith.Challinor3761 

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
Message 9 of 16
JhoelForshav
in reply to: JhoelForshav

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 🙂

 

Message 10 of 16

OK I will test again in the morning

Many thanks
Message 11 of 16

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")


 

Message 12 of 16

Hi @Keith.Challinor3761 

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

Message 13 of 16

The code would be to state which system the duct was used on W for waste, OM for oil mist, E for ends line this helps when we go to do Item numbers
Thanks for all your help the output at the moment is really good just need to refine a touch ,currently have THICKNESS_DIA_ANGLE_BENDRAD
Would like CODE_THICKNESS_DIA_ANGLE_BENDRAD_FLANGE so it would look like ( for example) W_2_350_ 60_2_FB
I have added code to the part file and replicated the lines used for the thickness but it fails with an error
Message 14 of 16

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

Message 15 of 16

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 

Message 16 of 16

@Keith.Challinor3761 

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 🙂

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

Post to forums  

Autodesk Design & Make Report