Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert List of Strings to Array of Strings

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
FarrenYoung
1496 Views, 2 Replies

Convert List of Strings to Array of Strings

I am trying to call a function on a .net object that takes an array of strings.

How can I convert my list of strings in Intent code to a .net object (array of strings) that I can use?

 

Here is my vba code (works fine):

Sub VBA_AddBlock()
    Dim attributes(2) As String
    attributes(0) = "1"
    attributes(1) = "2"
    attributes(2) = "3"

    Dim blk As AutoCADBlock
    Set blk = sheet.AutoCADBlocks.Add(blkDef, ptInsert, 0, 1, attributes, True)
End Sub

 

Here is my intent code (throws a parameter is incorrect error):

Dim mAttributes As List = {"1", "2", "3"}

tSheet.AutoCADBlocks.Add(tBlockDef, tInsertPoint, mRotation, mScale, mAttributes, mStatic?)

 

The mAttributes porition is the only issue I am having.  I can set that variable to NoValue and my block is added as expected which leads me to believe mAttributes just needs to be converted to the correct data type.

 

FWIW I can do this in .net by passing in the list to a parameter of my function like (ByVal mPrompts As Object).  I can pass that parameter directly to the Add function in .net so there is some conversion taking place when passing intent values to .net functions so I just need to figure that out so I can call the function inside intent on my .net object.

 

Thanks,

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
2 REPLIES 2
Message 2 of 3
AlexKorzun
in reply to: FarrenYoung

Hi Farren,

 

Try the following:

 

Rule Example 
     Dim lst As List = {"1", "2", "3"}
     Dim len = Length(lst)
	 
     Dim arrType = System.Type.GetType("System.String")
     Dim arr = System.Array.CreateInstance( arrType, len)
     
     
     For i = 1 To len
          arr.SetValue( nth(i, lst), i-1)
     Next
     
     Return arr
End Rule

 the output is:

Intent >example
--> {"1", "2", "3"}
Intent >example.GetType()
--> <System.String[]>

 Thank you,

 



Alex Korzun
Principal Engineer
Inventor Engineer-to-Order

Thank you,




Alex Korzun
Inventor-Revit Interop / Inventor-Fusion Interop / Inventor ETO
Autodesk, Inc.

Message 3 of 3
FarrenYoung
in reply to: AlexKorzun

Hey Alex,

Very nice bit of code! Just what I needed.

Thanks!

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************

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

Post to forums  

Autodesk Design & Make Report