Global Visibility Control of new WorkPlane across all Design View of Part model

Global Visibility Control of new WorkPlane across all Design View of Part model

Maxim-CADman77
Advisor Advisor
647 Views
11 Replies
Message 1 of 12

Global Visibility Control of new WorkPlane across all Design View of Part model

Maxim-CADman77
Advisor
Advisor

I'm developing a program that is supposed to create some set of WorkPlanes within a Part model. Those WorkPlanes are created with Visible property set to False.
It behaves as I need only if active Design View Representation was [Primary].
But if WorkPlne was created in non-Primary view active then when I later activate any other Design View those WorPlanes become visible.

 

I'd like to know how can I switch off visibility of the WorkPlane(s) upon creating by my program for ALL Design Views (independantly on which DVR was active).

 

PS:
I'm aware that WorkPlanes could be totally invisible if created construction but this is not applicable for my workflow (I need the WorkPlanes be user-accessible from Model Browser).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
648 Views
11 Replies
Replies (11)
Message 2 of 12

Maxim-CADman77
Advisor
Advisor

Manual workflow to disable WorkPlane Visibility for all Design Views - just switch Visibility off while "[Primary]" (?Master?) view is active ... but for some reason I can't achieve this (activate Primary-Master) by API.
I believe this is somehow related to the fact that API sees TWO "[Primary]" views: first (Master) and last (Transient) in DesignViewRepresentations collection (... or maybe I'm just dealing with wrong collection?) and by program I can NOT activate the Primary-Master (as soon as [Primary] is activated in Model Browser - the Primary-Transient occurs and gets active at API level).

 

Dear @johnsonshiue could you, please, re-check actuality of the help-page mentioned:
the DesignViewRepresentations is declared to be related to Assemblies ... with no mention of Parts.
But if so .. which collection reflects the Views of Parts?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 12

Maxim-CADman77
Advisor
Advisor

I still hope to get some inspiring ideas...

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 12

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.  Have you posted an idea in the Inventor Ideas forum about this yet?  If so you could post a link to it here, to maybe get more exposure, and initiate more votes for it.  This sounds like something that might be possible handle with an add-in, but I haven't taken the time to dig into all the available events that might be advantageous to monitor, and all the details of how to work around all the potential scenarios that could cause complications, such as multiple ModelStates, positional reps, derived stuff, and so on.  What we need is something similar to the little pencil icons next to the ModelStates, allowing us to either make changes that effect all DVR's, or just the active DVR.  That sound like a very logical, and useful added functionality that would blend in very well, giving an added level of control.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 12

Maxim-CADman77
Advisor
Advisor

No - I have a negative experience with Ideas.
Among of all my ideas only one was implemented ... 10 year after it was posted (after I've learned some programing  and developed my own AddIn-workaround for it).
... and I need some smart workaround/solution for the this task within my current life a week-or-two (otherwise I would be forced to do it in a non-smart way - by toggling visibility off within cycle through all DVRs...).

Please vote for Inventor-Idea Text Search within Option Names

Message 6 of 12

WCrihfield
Mentor
Mentor

I have been doing some snooping around amongst the events available, and so far not finding any really good looking results.  When monitoring UserInputEvents.OnActivateCommand, we can see when the command to 'toggle' visibility happens, and we can tell the difference between part or assembly by command name, but not the resulting visibility status, not what document is was involved, and not what object had its visibility changed.  Also while monitoring that same event, we can see when a new WorkPlane gets created, but same problem about not having a reference to the WorkPlane, or what document it is in.  And when monitoring the DocumentEvents.OnChange Event, we can see when a 'general' work feature is created or deleted, and although this one gives us a reference to the document involved, it does not give us a direct reference to the actual work feature object.  And since this event does not give us specifics about which type of work feature it was, we can't just get the last one of that type by its Index position in the collection (unless it is the only custom work feature in the document).  If this is possible at all, it may require monitoring multiple minor events at the same time, and somehow cross referencing what is going on between those multiple events.  Since I am not that experienced with creating add-ins yet, I'm not sure where to look next, or what the right combination of events might be, or how to cross reference the data between multiple events happening at the same time.

I hope you (or someone else here) can figure this out, because I am also interested in that type of ability.  Not just limited to work feature visibility, but components and other stuff too.  I know we can 'lock' DVR's, but more control is needed.  Good luck.  

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 12

nmunro
Collaborator
Collaborator

Is there any reason why you can't iterate over the design views collection and turn off the visibility of the work feature in each design view? If you are creating multiple work features you could hold references to all of them and then turn off the visibility of each of them in each design view. Turning off screen updating while doing this will help with the time to complete the operation. Seemed to work fine in a simple vba macro I tried.

        


https://c3mcad.com

0 Likes
Message 8 of 12

WCrihfield
Mentor
Mentor

Hi @nmunro.  That was a big part of the plan, but not the main point.  We also want that process to happen automatically when we add a new work feature (and/or component) and there are are multiple DVR's present, which is why I was looking into possible events that we could 'listen for' in the background to know when it takes place, and then hopefully get a reference to the work feature and the document it has been created in, so we can automatically react to those types of events by running a process like what you described on it, without needing to run an iLogic rule or VBA macro manually every time.  And if this were possible to completely automate this behavior, it would be nice if there was an easy way to turn that behavior on or off, as desired.  In one of the earlier posts he mentioned encountering multiple instances of the [Master]/[Primary] DVR though, causing problems with his attempts to automate the basic process, like what you mentioned.  We discussed that issue a bit more in the following similar parallel forum thread.

https://forums.autodesk.com/t5/inventor-programming-ilogic/issues-of-primary-part-design-view-doubli... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 12

nmunro
Collaborator
Collaborator

Ok. This can be done by working with the BeforeOrAfter parameter of the Document_OnChange event. I did this in an add-in so the structure in iLogic will be a bit different. Here is the approach I used.

  • In the DocumentEventsHandler class (persists while the add-in is loaded), I created a class level integer array to hold the current count of work planes, axes, and points in the part.
  • In the OnChange event handler, if DocType=Part and BeforeOrAfter = Before, check the Context parameter
    • If the Count = 3 and Item(1).ToString = "Create Work Feature" then you have the event of interest
  • So, save the current count of Work planes, axes, points in the array.
  • When the BeforeOrAfter argument is After, again check the DocType and Context for the same information.
    • If so, compare the current count of planes, axes, and points against the stored values prior to the creation of the new work feature.
    • One of them will be > than the previous count, so get the last item in the appropriate collection as the newly created work feature.
    • Iterate over all DesignViews (with error handling for Transient DVs?) and turn off the visibility of the new work feature.

The attached video shows the results of the above, without the code to hide the new work feature. The one issue I found was that the OnChange event actually fired twice, thus the double message boxes. I did not investigate this further.

 

 

Hope this helps.

 

        


https://c3mcad.com

Message 10 of 12

WCrihfield
Mentor
Mentor

Good idea about the shared counter.  I was actually testing individual events with custom event handlers I had created with Logic rules to check what data it would return when those events happened.  Perhaps in my case I could have used something like multiple SharedVariables too, but didn't think of it at the time.  Seems like a viable path towards a workaround at the moment, as long as you include something for cross-referencing which documents were involved.  Maybe something like a Dictionary(Of Document, List(Of Integer)) or Dictionary(Of Document, NameValueMap).  Just in case of maybe working through a large assembly by code process triggers the event a bunch of times for a bunch of different documents that are not the active document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 12

Maxim-CADman77
Advisor
Advisor

My main goal was to just escape any object-quantity-dependent post-processing (like switching objects' visibility off cycling through all those objects and DVRs).
My 2nd concern was potential UI language dependency and I got stuck/puzzled with inability to just activate the DVR #1

I believe the below code solves both:

 

Dim cmpDef = ThisDoc.Document.ComponentDefinition
Dim repMgr = cmpDef.RepresentationsManager

Dim initDVR = repMgr.ActiveDesignViewRepresentation
Dim initWPlsCount = cmpDef.WorkPlanes.Count

Dim invApp = ThisApplication

invApp.ScreenUpdating = False

If initDVR.DesignViewType <> DesignViewTypeEnum.kMasterDesignViewType Then repMgr.DesignViewRepresentations(1).Activate

''' <Your new object-creating code here>
''' Example:
	For Each wpl In cmpDef.WorkPlanes
		Dim newWPl = cmpDef.WorkPlanes.AddByPlaneAndOffset(wpl, 0)
		newWPl.Visible = False
	Next

If repMgr.ActiveDesignViewRepresentation.Name <> initDVR.Name Then repMgr.DesignViewRepresentations(initDVR.Name).Activate

invApp.ScreenUpdating = True

MsgBox("There were " + (cmpDef.WorkPlanes.Count - initWPlsCount).ToString + " new invisible WorkPlanes created.", , "Done")​

 

Your opinion, guys? Should this be marked as a solution?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 12 of 12

nmunro
Collaborator
Collaborator
Accepted solution

If you are doing this just as an iLogic rule then your proposed code looks good. The OnDocumentChange event handler would only be needed if you wanted to capture the manual creation of work features and hide them in all design views. It probably works better as a rule since users might be confused as to why their work features are always invisible to start.

 

Below is your rule with a bit of simplification. Activating DesignView(1) will always activate the Primary design view. It doesn't matter if it is noted as a transient design view, it is still the Primary design view. Capturing the current design view allows you to simply activate it at the end of the rule.

 

Dim invApp = ThisApplication
invApp.ScreenUpdating = False

Try
	
Dim cmpDef As PartComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim repMgr As RepresentationsManager = cmpDef.RepresentationsManager
	
Dim initDVR As DesignViewRepresentation = repMgr.ActiveDesignViewRepresentation

' activate primary design view
repMgr.DesignViewRepresentations(1).Activate

' add work planes
For Each wpl In cmpDef.WorkPlanes
	Dim newWPl = cmpDef.WorkPlanes.AddByPlaneAndOffset(wpl, 5)
	newWPl.Visible = False
Next

' reset active design view
If Not initDVR Is Nothing Then
    initDVR.Activate
End If

Catch
	
End Try

invApp.ScreenUpdating = True

 

        


https://c3mcad.com

0 Likes