Use parameter values ​​from documents opened with i-logic

Use parameter values ​​from documents opened with i-logic

leebrg
Contributor Contributor
287 Views
3 Replies
Message 1 of 4

Use parameter values ​​from documents opened with i-logic

leebrg
Contributor
Contributor

I want to run an external rule while the assembly called 'sample.iam' is open.

The content of the external rule is to open a new assembly called 'new.iam' and input the parameter inside 'sample.iam' to the parameter value of 'new.iam'.
However, it does not recognize the parameter of 'new.iam'.
I think it is because 'thisdocument' is 'sample.iam'.
Even if I activate the file of 'new.iam', it says that it cannot find 'new.iam'.
I tried the code below, but it says that it cannot find 'new.iam' itself.
Does anyone know how I can activate the newly opened file?

 

Sub Main
	
	'Defalt Value
	Dim oDoc As Document = ThisApplication.ActiveDocument
	Dim docName As String = ThisDoc.FileName
	Dim ModelName As String
	
	'Parameter
	Dim Type As String = Parameter("Type")
	Dim LoadSize As Integer = Parameter("Size")
	Dim TravelSize As String = Parameter("Travel")
	
	RefDocName = "C:\Temp\new.iam"

	Dim oRefDoc As Document = ThisApplication.Documents.Open(RefDocName, True)
	Dim Name As String = oRefDoc.DisplayName

oRefDoc.Activate parameter(Name, "HGR") = LoadSize parameter(Name, "TRV") = TravelSize End Sub 

 

0 Likes
Accepted solutions (1)
288 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

In this case it is better to use standard API instead of iLogic shortcuts.

Sub Main()

    'Defalt Value
    Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim docName As String = ThisDoc.FileName
    Dim ModelName As String

    'Parameter
    'Dim Type As String = Parameter("Type")
    'Dim LoadSize As Integer = Parameter("Size")
    'Dim TravelSize As String = Parameter("Travel")
    Dim Type As String = oDoc.ComponentDefinition.Parameters("Type").Value
    Dim LoadSize As Double = oDoc.ComponentDefinition.Parameters("Size").Value
    Dim TravelSize As String = oDoc.ComponentDefinition.Parameters("Travel").Value

    Dim RefDocName = "C:\Temp\new.iam"

    Dim oRefDoc As AssemblyDocument = ThisApplication.Documents.Open(RefDocName, True)
    Dim Name As String = oRefDoc.DisplayName

    oRefDoc.Activate()
    'parameter(Name, "HGR") = LoadSize
    'parameter(Name, "TRV") = TravelSize
    oRefDoc.ComponentDefinition.Parameters("HGR").Value = LoadSize
    oRefDoc.ComponentDefinition.Parameters("TRV").Value = TravelSize

End Sub
Message 3 of 4

Curtis_Waguespack
Consultant
Consultant

@leebrg, in addition to Michael.Navara's example, you could place the new.iam in the sample.iam , then transfer the parameter values, then delete the occurrence of new from sample, then open the new.iam.

 

Keep in mind that the iLogic Parameter function reads the parameter values in the document's units, so if sample.iam is in cm and new.iam is in inches, you'd need to do a conversion.

 

RefDocName = "C:\Temp\new.iam"

'add it to the original assembly
Dim newAssembly = Components.Add("new:1", RefDocName, visible := False)

'copy over the parameter values
parameter(newAssembly.Name, "HGR") = Parameter("Size")
parameter(newAssembly.Name, "TRV") = Parameter("Travel")

'remove the component from the assembly
newAssembly.Occurrence.Delete2(True)

'open  it
Dim oRefDoc As Document = ThisApplication.Documents.Open(RefDocName, True)

EESignature

0 Likes
Message 4 of 4

leebrg
Contributor
Contributor
Your answer solved my problem.
Thank you so much.!!! 🙂
0 Likes