Layers causing drastic changes in loading time

Layers causing drastic changes in loading time

CflowAutodeskAdmin
Participant Participant
1,693 Views
16 Replies
Message 1 of 17

Layers causing drastic changes in loading time

CflowAutodeskAdmin
Participant
Participant

Hi,

 

Recently I've gathered some bits and pieces of iLogic code from this forum to change the layer on specific parts/assemblies in a drawing. This is working as intended, but a colleague of mine noticed a drastic change in loading time when updating the drawing after changes to the model, after using this iLogic. He did some testing, and measured the time it took to update the drawing:

 

1: No extra layers or colors on drawing : about 3 minutes (yes, it is a big assembly/drawing)

2: Change color by selecting component(s) in browser, right click, properties and then choose color: about 6 minutes

3: Using the iLogic code to change layer on selected components: 1 HOUR and 5 minutes before he eventually gave up, and forced Inventor to shut down.

 

How can changing layer on a couple of components in a drawing cause this extreme change in loading time?

Or could it be something with the iLogic code thats causing the drawing to be corrupted/damaged somehow?

 

Has anyone experienced similar issues? Or maybe an idea of what's causing it?

Attached the iLogic code.

1,694 Views
16 Replies
Replies (16)
Message 2 of 17

sundars
Autodesk
Autodesk

Hi @CflowAutodeskAdmin 

 

Thank you for posting your findings. You are correct about the timings.

 

Layer Color (Fastest)

change is the fastest as we simply change the layer and re-render the drawing sheet. All entities then look at the layer color and render themselves with that color.

 

Part Color (UI: select part from drawing browser and change color via properties)

We have to apply individual color override on the part first and it's slower than layer because we have to navigate to the part data structure in the scene, apply color and re-render it.

 

Individual Edge Colors (UI: aka select edges via UI and then change properties) (Slowest)

Slowest as we have to process each curve and apply a color

 

In your script, because you are collecting ALL drawing curves for your input component occurrences, this basically falls to the 3rd method (individual edge colors) and will be slow.

 

Unfortunately, I dont think we have an equivalent in the API to apply the part color just like the UI and thats probably the reason why you see the difference in behavior between UI and API.

 

Hope that helps

-shiva

Shiva Sundaram
Inventor Development
0 Likes
Message 3 of 17

CflowAutodeskAdmin
Participant
Participant

Hi @sundars, thanks for your reply!

 

How do you do it the fastest way (what you refer to as "Layer Color")?

There is no way to do it the fastest way with iLogic?

0 Likes
Message 4 of 17

sundars
Autodesk
Autodesk

Hi @CflowAutodeskAdmin 

 

So, to change layer color via iLogic, try the following code snippet

1. create a rule and paste the following code in there and run

2. this will create a color of red and set the "visible (ansi)" layer color to red

 

oC = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
ThisDrawing.Document.StylesManager.Layers.Item("Visible (ANSI)").Color = oC

You could play with the layer name and/or create other statements to manipulate layer properties.

 

Let me know if it works.

 

Thanks

-shiva 

Shiva Sundaram
Inventor Development
Message 5 of 17

chandra.shekar.g
Autodesk Support
Autodesk Support

@CflowAutodeskAdmin,

 

@sundars looks perfect. Let me know if it works.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 17

CflowAutodeskAdmin
Participant
Participant

@sundars @chandra.shekar.g 

Hi, sorry for the late reply.

 

Yes, it works for changing the layer color. But then it changes the color on all parts in the assembly. 

The way I had it, we could write in the part/sub-assembly name, and then the color changes on said part/sub-assembly in all views.

 

Could you please explain how I can do the same with the code snippet you posted?

Many thanks!

0 Likes
Message 7 of 17

WCrihfield
Mentor
Mentor

Have you considered:

- Within the sub-component, create a new view representation, then set its appearance to the color/appearance you need, then give that view representation a name to reference from the assembly level.

- Within the main assembly, create a new view representation in which that sub-component's view representation is set to that named one above, then give this rep a name to reference from the drawing level.

- Within the drawing, set your drawing view's view representation to the one named in the assembly.

This would be much easier & faster to implement, and should give you a similar result.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 17

sundars
Autodesk
Autodesk

Hi @CflowAutodeskAdmin 

 

I think what you want it to change color of a component by assigning it to a layer. However, layers are typically associated with drawing curves - not components. This is because a component in a drawing view can have different types of curves (visible, hidden etc.). So, you cannot reassign a component to a layer - instead you can directly set the color on the component. Internally the rendering process would override the default color of the component and render the component's curves in a different color. That would still be faster than selecting each curve individually and assigning a layer to it.

 

Can you try that?

-shiva

 

Shiva Sundaram
Inventor Development
0 Likes
Message 9 of 17

CflowAutodeskAdmin
Participant
Participant

Hi @sundars 

 

When you say "...instead you can directly set the color on the component." do you mean right-click the part/assembly in the drawing model browser -> Properties -> Color? Or changing the color of the part/assembly in the assembly environment and somehow transferring that information to the drawing?

 

Thanks!

 

 

0 Likes
Message 10 of 17

sundars
Autodesk
Autodesk

Hi @CflowAutodeskAdmin 

 

I was referring to setting component color from the drawing browser by selecting the component and setting a color - as opposed to selecting edges and applying color on the edges. Changing the color in the assembly will work with shaded views where the component faces are rendered in the model color (not edges). Drawing curves are always rendered in the drawing color (default is by layer OR user applied color override). 

 

Thanks

-shiva

Shiva Sundaram
Inventor Development
0 Likes
Message 11 of 17

frederic.vandenplas
Collaborator
Collaborator

The best way to speed up things is create on ore more collections of items and change the collection to a specific layer or whatever you want to do with the collection.

I had to do this with a couple of hundreds lines of a model in the drawing environment and i took minutes (you see them actually one by one changing) a collection did it in a second

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 12 of 17

Anonymous
Not applicable

Hello, could you have the final code.
But how to do to give the name to the layer instead of the color with the name you put in the question, so as to have the name equal to the subassembly.
Thank you very much - f.sansottera4TBLW

0 Likes
Message 13 of 17

CflowAutodeskAdmin
Participant
Participant

Hi @Anonymous 

 

Unfortunately I have not had the time to work more on this code.

 

But, if I understand your question correctly it should work to change where it says "....("blue")"to "....(myNumber)"

 

GSchmiedt_0-1630926482219.png

 

0 Likes
Message 14 of 17

CflowAutodeskAdmin
Participant
Participant

Would you be willing to share that code if you still have it?

0 Likes
Message 15 of 17

WCrihfield
Mentor
Mentor

Hi @CflowAutodeskAdmin.  In a sense, you are already using the 'fastest' (layers) method (specified by Sundars), and the collection method (mentioned by frederic.vandenplas), because the actual action of changing the color/layer of stuff you are using down in your original code is basically Sheet.ChangeLayer(collection, layer).  You added all the drawing curve segments of a component found in the drawing view to an object collection, then used that method to change all the objects in that collection to a specified layer at once.  That process should be about as quick and simple as it can get when doing this by iLogic.  However, like most things, it's easier to say the task, than it is to create code to make the task happen, and there is a lot more code involved here than just what's needed for that process.  There are 5 For Each loops, each going to deeper levels, and each level deeper exponentially adds to the number of checks or actions that are being performed by the code.  Then you include the process of creating a new local copy of a layer, then setting the color and line type of that layer that you want to change the objects to, instead of simply having a layer ready to use ahead of time.

 

It looks like the largest portion of your code is used to identify and get the component that you want to effect in the drawing view.  Since you are currently interrupting the rule with an InputBox to ask the user for a number, then attempting to find that component using that number, I wander if it might simplify or improve performance to have the user select a drawing curve segment directly, using the Pick method, then get the component that the curve belongs to using a few levels of oObject.Parent.  I'm not 100% sure if this step would greatly improve performance, but it's something to think about.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 16 of 17

Anonymous
Not applicable

Hello dear Mr GSchmiedt it works and it is much faster it would be interesting if it also asked for the name of the layer and the possibility of entering it, if the layer already existed it would not overwrite it or make another one, the color is relative this because where I work unfortunately it is exported to Autocad Mechanical thus losing the associativity
unfortunately this is the case.
The color does not matter because we use a dwt file with the colors already some layer names then we always change the colors in Autocad.
It is possible to make a rule that punches as mentioned above an equal but with the ability to immttere the color "Red color".
"255,0,0" always with the questions I enclose image of the background file.
Thank you very much you are very very good

Translated with www.DeepL.com/Translator (free version)

fsansottera4TBLW_0-1631083685304.png

 

0 Likes
Message 17 of 17

CflowAutodeskAdmin
Participant
Participant

Hi @WCrihfield,

 

Thanks for your input! Much appreciated.

I am by no means a coder, I have just learned some iLogic by trying and failing, and picking bits and pieces of code from this forum and google.

 

But what you are saying does make a lot of sense and got me thinking.

 

Thanks!

0 Likes