wild iLogic/asset idea: Insert/Connect asset at every unused connector?

wild iLogic/asset idea: Insert/Connect asset at every unused connector?

matthew_neesley
Collaborator Collaborator
2,500 Views
17 Replies
Message 1 of 18

wild iLogic/asset idea: Insert/Connect asset at every unused connector?

matthew_neesley
Collaborator
Collaborator

Say I have a really long run of conveyor beds, each with a support connector.  Is there some crazy iLogic way I could automatically drop in a specified support-leg-asset and connect it to the unconsumed specified connector on each conveyor bed?

0 Likes
2,501 Views
17 Replies
Replies (17)
Message 2 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@matthew_neesley,

 

Can you please provide non confidential data (simplified conveyor) and image to illustrate the behavior before and after asset assigning to support or connector?

 

Please specify the asset name and library name as well.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 18

matthew_neesley
Collaborator
Collaborator

Recapping and expanding:  I am trying to have a grand scheme where conveyor leg assets are automatically added/connected to previously-placed conveyor bed assets; then the legs get resized so that they end up touching the ground at global z coordinate zero.  I think that’s definitely possible because I noticed that when the legs are connected to the beds and resized, they grow downwards and don’t disturb the position of the beds they are attached to.

(Before you suggest it:  Yes, the beds need to be physically separate assets from the legs, for various reasons, both in Inventor and when the layout is synched to ACAD.)

One quick way I think this “could” work:  (I’ll assume for a second that the global coordinate values of the connectors themselves cannot be extracted as targets for asset insertion….am I right?)  I would insert “dummy features” in every asset that are aligned dead center with the connectors.  Then iLogic would gather up all of the global coordinate sets for these features, and use them as insertion points for new assets (the legs).

More about the procedure:  New legs would be inserted so that their connectors end up on top of each other.  Then the “infer connectors” command would be run, and since they are literally on top of each other, the permanent connection is automatically made.

-----------------------------------------------------------------------------------------------------------------------------------------

Then I moved onto this line of thinking:

Each conveyor bed has a connector for a leg.  I tried using some iLogic “insert components code at these coordinates”, but when the assets are inserted this way, there are no connectors showing at all, so I’m guessing that assets MUST be dragged off the palette to function as assets with proper connectors.  Oh, well…so then I did some research and came across this:

https://knowledge.autodesk.com/support/factory-design-utilities/learn-explore/caas/CloudHelp/cloudhe...

This seems to be what I’m after…but the programming language is a little over my head; why do I need that long name for the asset?  I’m just getting one off the palette, and how can it have an instance number before I even insert it/drag it off the palette?

Also, when trying to do this…do I need to be concerned about the alignment of one asset to another?  If that’s the case:

Depending on the global, long-axis orientation of the bed, the leg will either come in aligned perfectly or 90 degrees off (before it’s “connected”)

To solve the alignment problem: Could iLogic be used to align one feature in a part (Factory Asset) with another? 

That’s the long-and-short of it.  I’d gladly pay for help/write it all for me thru Paypal if that helps. 

 

How do I need to provide the assets in question to anyone?  I've never been clear on the folder structure of assets in general.  Would you need just the .ipt file or the whole folder for the asset itself?

0 Likes
Message 4 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@matthew_neesley,

 

Currently, factory API  mainly focus on operation (add, modify, collect) the asset instance in the layout.

 

Online help documentation for Factory API is available at below link.

 

https://help.autodesk.com/view/FDU/2019/ENU/?guid=FDU_Factory_Design_Tools_API_Application_Programmi...

 

 

There is API sample code for inventor on the git:

 

https://git.autodesk.com/factory-design/factory-design-utilities/tree/master/Tools/FactoryPublicAPIv...

 

For using the FactoryAPI in iLogic, here is example:

 

  1. Create Factory layout
  2. Open ilogic browser
  3. Click Rules tab
  4. Right click > Add Rule
  5. Click header, add following code

 

AddReference "Autodesk.Factory.PublicAPI.dll"

AddReference "PresentationCore.dll"


Imports Autodesk.Factory.PublicAPI.Currency.v2

Imports Autodesk.Factory.PublicAPI.Objects.v2

    In main area of code, add following code, and save the rule


Sub Main()

Dim Layout As AssemblyDocument

Layout = ThisApplication.ActiveDocument


Dim api As IFactoryAPI

api = Autodesk.Factory.PublicAPI.API.Instance


Dim newInst As AssetInstance

newInst = New AssetInstance


newInst.AssetID = "a1ec8fba-9573-4ac3-8c9d-e8a217ddef1e"

newInst.Position = New System.Windows.Media.Media3D.Matrix3D


Dim instances = New IAssetInstance() { newInst }

api.AddAssetInstances(Layout, instances)

End Sub

 

 

You can run the rule, or create from to invoke the rule for easy use.

 

Precondition: Make sure inventor factory installed

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 18

matthew_neesley
Collaborator
Collaborator
Great, thanks very much for the follow up, much appreciated!
0 Likes
Message 6 of 18

matthew_neesley
Collaborator
Collaborator

One of your links is invalid!

 

https://git.autodesk.com/factory-design/factory-design-utilities/tree/master/Tools/FactoryPublicAPIv...

 

Can you provide me with a working link for this info?

0 Likes
Message 7 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

@matthew_neesley,

 

Source code is attached with this post.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 18

matthew_neesley
Collaborator
Collaborator

How do I input an actual set of coordinates?  The coding style you used in that nice example you provided me, unfortunately, doesn't match here:

 

https://knowledge.autodesk.com/support/factory-design-utilities/learn-explore/caas/CloudHelp/cloudhe...

 

That link shows entering coordinates with offsets, but that code won't work in your example here.

 

 

 

0 Likes
Message 9 of 18

Kenny
Autodesk
Autodesk

Hi mneesley,

 

Thanks for your posting.

 

You are talking about code in iLogic (which is VB script) is different from the code in the link (which is C#), there are similar code implement using different language. My understanding is that: you want to use Factory API insert asset instance into specific position in logic, you need know how to set position there, correct?

 

Here is example:

In logic browser

Add Header:

AddReference "Autodesk.Factory.PublicAPI.dll"
AddReference "PresentationCore.dll"

Imports Autodesk.Factory.PublicAPI.Currency.v2
Imports Autodesk.Factory.PublicAPI.Objects.v2

Main code area:

Sub Main()
Dim Layout As AssemblyDocument
Layout = ThisApplication.ActiveDocument

Dim api As IFactoryAPI
api = Autodesk.Factory.PublicAPI.API.Instance

Dim newInst As AssetInstance
newInst = New AssetInstance

newInst.AssetID = "f7d84241-cb84-40fb-8a69-c36c50eb3f41" '<<<<Make sure System\Architecture\Furniture\Chair download
newPos = New System.Windows.Media.Media3D.Matrix3D()
newPos.OffsetX = 100 '<<<<Set position here
newPos.OffsetY = 100
newPos.OffsetZ = 0
newInst.Position = newPos

Dim instances = New IAssetInstance() { newInst }
api.AddAssetInstances(Layout, instances)
End Sub

Hope this can resolve your issue.

If you still have issue, please let us know.

 

Thanks

Kenny

0 Likes
Message 10 of 18

matthew_neesley
Collaborator
Collaborator

Thanks!  I'm getting closer...

 

How do I input multiple sets of coordinates?  Say I've got something like 120 instances of my leg asset I need to put into a factory layout, all at different spots?

 

If this is all of a sudden a whole new can of worms, please let me know.  It seems to me that this kind of command is meant to be used for multiple insertions of the same part.  

 

Thanks again for all your help; this is the very last piece of the puzzle I need.

0 Likes
Message 11 of 18

Kenny
Autodesk
Autodesk

Hi mneesley,

 

Good to know you get closer to your goal 🙂

 

For your new requirement, basically, you need prepare a list containing which asset insert to which position, then insert asset instance based on the list.

Here is example based on last post to show the idea: I build the list in using a csv file.

Please please put attached instances.csv file into c:\temp\ folder before your run the script.

 

Sub main()	
	Dim FilePath As String
	FilePath = "C:\temp\instances.csv"
	lines = System.IO.File.ReadLines(FilePath)
	For Each line In lines
		item = Split(line, ",")		
		If Not IsNumeric(Item(1))
			Continue For	
		End If
		
		id = Item(0)
		x = CInt(Item(1))
		y = CInt(Item(2))
		z = CInt(Item(3))
        InsertAsset(id, x, y, z)       
	Next
End Sub

Sub InsertAsset(id, x, y, z)
	Dim Layout As AssemblyDocument
	Layout = ThisApplication.ActiveDocument

	Dim api As IFactoryAPI
	api = Autodesk.Factory.PublicAPI.API.Instance

	Dim newInst As AssetInstance
	newInst = New AssetInstance

	newInst.AssetID = id '<<<<Make sure System\Architecture\Furniture\Chair download
	newPos = New System.Windows.Media.Media3D.Matrix3D()
	newPos.OffsetX = x '<<<<Set position here
	newPos.OffsetY = y
	newPos.OffsetZ = z
	newInst.Position = newPos

	Dim instances = New IAssetInstance() { newInst }
	api.AddAssetInstances(Layout, instances)
End Sub

 

Thanks

Kenny

 

Message 12 of 18

matthew_neesley
Collaborator
Collaborator

Hello again Kenny:

I've gotta ask for your help again.  After all these assets (legs) get inserted, I need to adjust all their heights to specific values.  I tried to do it this way:

https://forums.autodesk.com/t5/inventor-customization/need-some-help-getting-parameters-in-an-excel-...

...but then came to the possible, unfortunate realization that I might have to go through the API again, as opposed to trying to do simple iLogic (umm...right?)

 

I've attached a file that shows the data set.  Each leg asset instance that's in the assembly needs to have its parameter called "TOS" updated to the specified number in column "B". 

 

If this is possible thanks very very very much as usual for your help 🙂

 

0 Likes
Message 13 of 18

Kenny
Autodesk
Autodesk

Hi mneesley,

 

Factory API do support update instance using parameter; I modify the csv as: which asset insert to which position with which parameter; I enhance the script support update with parameter.

 

Please copy the attached instances_para.csv under C:\temp\

AddReference "Autodesk.Factory.PublicAPI.dll"
AddReference "PresentationCore.dll"
Imports Autodesk.Factory.PublicAPI.Currency.v2
Imports Autodesk.Factory.PublicAPI.Objects.v2

Sub main()
	lines = System.IO.File.ReadLines("C:\temp\instances_para.csv")
	For Each line In lines
		cells = Split(line, ",")
		
		'Title line skip it
		If Not IsNumeric(cells(1))
			Continue For	
		End If
		
		'Get settings
		id = cells(0)
		x = CInt(cells(1))
		y = CInt(cells(2))
		z = CInt(cells(3))
		paras = cells(4)
		
		'Insert asset
		InsertAsset(id, x, y, z, paras)
	Next
End Sub

Sub InsertAsset(id, x, y, z, paras)

	Dim Layout As AssemblyDocument
	Layout = ThisApplication.ActiveDocument
	
	Dim api As IFactoryAPI
	api = Autodesk.Factory.PublicAPI.API.Instance
	
	'Set init value
	newInst = New AssetInstance
	newInst.AssetID = id
	newPos = New System.Windows.Media.Media3D.Matrix3D()
	newPos.OffsetX = x
	newPos.OffsetY = y
	newPos.OffsetZ = z
	newInst.Position = newPos
	
	'Add instance in
	createdInsts = api.AddAssetInstances(Layout, New IAssetInstance() { newInst })	
		
	'update instance parameter
	createdInst = createdInsts(0)
	If (Not String.IsNullOrEmpty(paras))

		'Parse the parameters
		paraItems = Split(paras, "|")
		For Each paraItem In paraItems
			paraItemSections = Split(paraItem, ":")
			paraName = paraItemSections(0)
			paraValue = paraItemSections(1)
			
			'Make sure parameter name correct
			If createdInst.Parameters.ContainsKey(paraName)
				createdInst.Parameters(paraName) = paraValue
			End If
		Next
		
		'update instance
		api.UpdateAssetInstances(Layout, New IAssetInstance() {createdInst })
		
	End If	
End Sub

Notes
In the instance_para.csv, parameter input follow my custom rule:
<parametername>:<parametervalue>|<parametername>:<parametervalue>|<parametername>:<parametervalue>..

You can create and interpret your rule by self 🙂

 

Hope it helps.

 

Thanks

Kenny

0 Likes
Message 14 of 18

matthew_neesley
Collaborator
Collaborator

I see, that's pretty cool how you wrote code to both insert AND change parameters in one Rule.

 

Except, unfortunately, my assets aren't cooperating fully.  I've attached a screenshot of what's going on, the CSV file I used, and the asset in question.  It flashes at the correct height momentarily, but then it shortens to 10" every time and doesn't end up at the correct "Z" elevation.

 

As always whatever you can do to help, I greatly appreciate.  Thanks!

0 Likes
Message 15 of 18

matthew_neesley
Collaborator
Collaborator

OMG...I figured it out!  Your info is in cm....and I'm using inches.  It works FLAWLESSLY! 🙂  THANKS SO MUCH!

0 Likes
Message 16 of 18

Kenny
Autodesk
Autodesk

Hi mneesley,

 

Good to know, you resolved your problem by yourself, good job~  🙂

Yes, exactly, the unit for parameter is cm, you need convert it before inputting  it in the csv file.

 

Thanks

Kenny

0 Likes
Message 17 of 18

matthew_neesley
Collaborator
Collaborator

Thanks very much for all the help on this thread, my coworkers love it!!

0 Likes
Message 18 of 18

marcos.pellizzoni
Enthusiast
Enthusiast

Hi

 

Were you able (or needed) to align one asset with the other when inserting?

 

Thanks

 

Marcos Pellizzoni

Mechanical Engineer
AutoCAD Certified Professional 2015
0 Likes