Change the active row of the iPart table using iLogic

Change the active row of the iPart table using iLogic

harvey_craig2RCUH
Advocate Advocate
342 Views
3 Replies
Message 1 of 4

Change the active row of the iPart table using iLogic

harvey_craig2RCUH
Advocate
Advocate

I have written a code that adds a new row the iPart table with a new length. I have simplified it for this post. How do I get the script to make the new row active? Here is what I have written:

Dim oFactoryDoc As PartDocument
oFactoryDoc = ThisApplication.ActiveDocument

Dim oPartFactory As iPartFactory
oPartFactory = oFactoryDoc.ComponentDefinition.iPartFactory

oWS = oPartFactory.ExcelWorkSheet
oWS.Cells(5, 1) = "this is member 5" 'Member name
oWS.Cells(5, 2) = "this is member 5" 'Part name
oWS.Cells(5, 3) = 30 'Length

oWS.Parent.Save
oWS.Parent.Close

'Here I want to change the active row to the new row I've just created, how do i do this? I think it's something along these lines?
iPartMember.ChangeRow(5)

I have read the iPartMember.ChangeRow page and it says the first argument is NewRow which can be a RowIndex, which in this case should be 5? And the second argument is for custom entry which I've left blank as it's optional. I get this error when I try to run the code:

harvey_craig2RCUH_0-1717152755017.png

 

How do I get it to change to the new row?

 

Thanks,

Harvey

0 Likes
343 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @harvey_craig2RCUH.  I think what you are looking for is the following property of the main iPartFactory object.  When you set that property do a specific iPartTableRow object, it will make that the default one, and will 'activate' that version of the model.  But since you are going through the ExcelWorkSheet route, you are not left with a reference to the specific row object that you were working with, so you would have to go through the iPartFactory.TableRows property to get the iPartTableRows collection to get a reference to the specific iPartTableRow object you will need to supply as its value.

iPartFactory.DefaultRow 

Edit:  That other line of code may have failed for two reasons.  First, you have not defined the 'iPartMember' variable you were attempting to use there.  That is the name of an object type, but you must have previously obtained a reference to a specific iPartMember object first, otherwise it has no meaning.  Second reason for failure, is that the documentation says this will only work for 'custom' members (not standard iPart members).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

harvey_craig2RCUH
Advocate
Advocate

I have tried to follow this but I've never been able to understand how to create scripts out of the Autodesk documentation. This is what I tried with my errors. Where can I learn how to decipher the Autodesk documentation?

harvey_craig2RCUH_0-1717162608139.png

Or how far off am I with this attempt?

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @harvey_craig2RCUH.  You basically always have to start from some object that you already have a reference to, before you can get access to something below that object.  Because of this, it is throwing an error at Line 16

oPartTableRows = iPartFactory.TableRows

(and the other two).  This because, when trying to set an initial value to your new 'oPartTableRows' variable, you are using 'iPartFactory.TableRows' when 'iPartFactory' has no value, because 'iPartFactory' is just the name of an object Type, and not a variable representing an actual reference to an existing iPartFactory object.  You should have used the 'oPartFactory' variable there, which was already established earlier in the code, so the new value would have been set like this:

oPartTableRows = oPartFactory.TableRows

...because it is accessing the TableRows property of that instance of an iPartTable that we found earlier in the code.  That is the main reason we established the 'oPartFactory' variable earlier in the code, so we can use that variable for accessing that specific instance later, to dig deeper into it.

 

Then at Line 19, the same situation is happening again.  You are trying to access a specific iPartTableRow object from just the name of a Type of object, and not from a variable that actually represents an existing instance of an object.  So, this:

oPartItem = iPartTableRows.Item(4)

...should have been like this:

oPartItem = oPartTableRows.Item(4)

...because the variable 'oPartTableRows' is what actually represents an existing instance of the collection, while 'iPartTableRows' is just the name of a Type of object.

 

Then at Line 21, it threw an error because the variable 'oPartItem' did not have a proper value assigned to it yet, because of what happened on Lines 16 & 19.

 

I took the time to type all that out so that you might understand how this model based code system is supposed to work.  There are certain 'keywords', and object types that we should only use in certain places, such as when declaring the type of a new variable, then there are 'variables', which are custom text that we create just to represent some object or data that we want to assign to it, for use later.  We must navigate the object model to find objects, then objects have properties, methods (subs & functions), and events.  We usually use the properties of a higher level object to access the objects below that object.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes