Navisworks API

Reply
Distinguished Contributor
bthatcher
Posts: 724
Registered: ‎12-12-2003
Message 1 of 2 (124 Views)

item.Parent.Model.RootItem

124 Views, 1 Replies
01-18-2013 10:00 AM

I have a selected modelitem and i'm trying to get the model that it is in and add it to a modelitemcollection.

 

foreach (ModelItem item in selectedItems)
{                    
   collection.Add(item.Parent.Model.RootItem);
}

 I am getting the error "Object reference not set to instance of object". How can I acomplish this? Thanks.

Active Contributor
ngombault
Posts: 45
Registered: ‎11-14-2012
Message 2 of 2 (116 Views)

Re: item.Parent.Model.RootItem

01-20-2013 02:20 PM in reply to: bthatcher

Hi,

 

Have you tried using the AppInfo tool from Navisworks sample code? this wouls help you find out what is thowing the error. So far I have 2 guesses:

 

First, is your collection initialized? (new collection)

 

Second, only the RootItem has a value for the Model property: RootItem.Model; so if your item is a 1st level child of the RootItem, then you can access this property with Item.Parent.Model; but if your item is a N-th level children then you need to call the parent method N-times: Item.Parent.Parent.Parent.....Model.


You may need a recursive method.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community