Exception thrown if changing attributes e.g. transparency

Exception thrown if changing attributes e.g. transparency

christoph.schillingLHCFR
Participant Participant
574 Views
3 Replies
Message 1 of 4

Exception thrown if changing attributes e.g. transparency

christoph.schillingLHCFR
Participant
Participant

Hey,

 

we are using the dll Autodesk.Navisworks.Api in a custom developed Plugin. In this Plugin we use different apis, e.g. find an element or focus an element.

But we also want to set a general transparency to the full model for example.

Reading apis are working fine, but if we want to change something like transparency, then we get following message and Simulate is closing:

Exception thrown at 0x00007FFCA863AF30 (lcutil.dll) in Roamer.exe: 0xC0000005: Access violation reading at position 0x0000000000000000

 

Below you can find the source:

try
{
Document localDocument = Application.ActiveDocument;

var collection = localDocument.Models.CreateCollectionFromRootItems();

localDocument.Models.OverridePermanentColor(collection, Color.FromByteRGB(color.R, color.G, color.B));

}
catch (Exception ex)
{
Logger.Error(ex);
}

 

Does anyone had the same Issues?

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

ulski1
Collaborator
Collaborator
That is not how you set transparency the method is OverridePermanentTransparency
Beware that transparency is a double.
Change your code to use using statement whenever you use disposable objects like so:

using (ModelItemCollection searchResultCollection = searchObject.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false))
{
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentTransparency(searchResultCollection, mytransparency);
}

- also I recommend that you install the Visual Studio extension DisposableFixer

Br
Ulrik

0 Likes
Message 3 of 4

christoph.schillingLHCFR
Participant
Participant

Hey Ulrik,

sorry for that mistake with the code. I copied the wrong lines of my source code.

I have tried your proposal with dispose:

Document localDocument = Application.ActiveDocument;

using(var collection = localDocument.Models.CreateCollection())
{
localDocument.Models.OverridePermanentTransparency(collection, value);
}

but I am always getting the same error. Value hast the type double.

 

Many thanks for your hint with DisposibleFixer. I have installed it.

 

Greetings Chris.

0 Likes
Message 4 of 4

ulski1
Collaborator
Collaborator
Createcollectionfromrootitem returns a ModelItemCollection but OverridePermanentTransparency takes a IEnumerable check if that is your problem
0 Likes