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,
Solved! Go to Solution.
Solved by AlexKorzun. Go to Solution.
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
Hey Alex,
Very nice bit of code! Just what I needed.
Thanks!