Message 1 of 21
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
How to select all dimensions in one view?
Or how to check to which view the dimension belongs?
Solved! Go to Solution.
Hello,
How to select all dimensions in one view?
Or how to check to which view the dimension belongs?
Solved! Go to Solution.
try this
Dim oDDoc As DrawingDocument = ThisDrawing.Document Dim oSheet As Sheet = oDDoc.ActiveSheet 'Dim oDim As LinearGeneralDimension For Each oDim In oSheet.DrawingDimensions.GeneralDimensions Try 'linear dimension If oDim.IntentOne.Geometry.Parent.Name = "VIEW2" oDDoc.SelectSet.Select(oDim) End If Catch 'circle dimension If oDim.Intent.Geometry.Parent.Name = "VIEW2" oDDoc.SelectSet.Select(oDim) End If End Try Next
Hi @Hubert_Los. This is not an easy task to achieve, because according to Inventor's API, dimensions in a drawing belong to the sheet they are on, instead of to whatever view they may be attached to geometry within. There is no existing built-in tool or method designed by Autodesk and exposed for us to use, either within Inventor's API system, or in the iLogic snippets, that would easily tell us which view a given drawing dimension may be associated with. A tool like that would be a great idea, and definitely helpful, but does not exist yet.
There are still ways that we can attempt to figure this out by code, but there are a whole lot of variables involved that make any code solution of this type very long and complicated, and may still not be 100% effective or error proof. We basically have to inspect if a dimension is attached to anything, what is it attached to, and where on that object it is attached. If it is attached to certain kinds of geometry, then we may be able to dig down further and find out what view that geometry belongs to. But sometimes it is just something like a Point2d, which does not have a parent entity, and therefore no directly associated view. One other method some have used, as a last resort, is to check if certain points associated with the dimension's geometry are within the bounds of any one specific drawing view, and not any other views, as a process of elimination.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @Hubert_Los. Below is an example iLogic rule I created for situations like this. It uses a custom Function I created, which allows you to supply a DrawingDimension object to it, and it may or may not return a DrawingView object that is associated with the supplied DrawingDimension. To simplify testing, I am just prompting the user to manually select a drawing view first, then it will search through all dimensions on the same sheet as the selected view, and gather any dimensions that may be associated with the selected view into a List of dimensions. Then it lets you know in a message how many were found. Then it selects them all.
Sub Main
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, oPrompt)
If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Exit Sub
Dim oView As DrawingView = oObj
Dim oSheet As Sheet = oView.Parent
Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
Dim oViewDims As New List(Of DrawingDimension)
For Each oDDim As DrawingDimension In oDDims
If Not oDDim.Attached Then Continue For
Dim oDimView As DrawingView = GetDimensionView(oDDim)
If IsNothing(oDimView) Then Continue For
If oDimView Is oView Then
If Not oViewDims.Contains(oDDim) Then oViewDims.Add(oDDim)
End If
Next
MsgBox("There were " & oViewDims.Count & " dimensions found for the selected view.", , "")
If oViewDims.Count > 0 Then
Dim oDDoc As DrawingDocument = oView.Parent.Parent
For Each oViewD In oViewDims
oDDoc.SelectSet.Select(oViewD)
Next
End If
End Sub
Function GetDimensionView(oDDim As DrawingDimension) As DrawingView
If IsNothing(oDDim) OrElse oDDim.Attached = False Then Return Nothing
Dim oGIntents As New List(Of GeometryIntent)
Select Case TypeName(oDDim)
Case "AngularGeneralDimension"
Dim oAGD As AngularGeneralDimension = oDDim
Try : oGIntents.Add(oAGD.IntentOne) : Catch : End Try
Try : oGIntents.Add(oAGD.IntentTwo) : Catch : End Try
Try : oGIntents.Add(oAGD.IntentThree) : Catch : End Try
Case "DiameterGeneralDimension"
Dim oDGD As DiameterGeneralDimension = oDDim
Try : oGIntents.Add(oDGD.Intent) : Catch : End Try
Case "LinearGeneralDimension"
Dim oLGD As LinearGeneralDimension = oDDim
Try : oGIntents.Add(oLGD.IntentOne) : Catch : End Try
Try : oGIntents.Add(oLGD.IntentTwo) : Catch : End Try
Try : oGIntents.Add(oLGD.IntentThree) : Catch : End Try
Try : oGIntents.Add(oLGD.VirtualArcPosition) : Catch : End Try
Case "RadiusGeneralDimension"
Dim oRGD As RadiusGeneralDimension = oDDim
Try : oGIntents.Add(oRGD.Intent) : Catch : End Try
Case "OrdinateDimension"
Dim oOD As OrdinateDimension = oDDim
Try : oGIntents.Add(oOD.Intent) : Catch : End Try
End Select
If oGIntents.Count = 0 Then Return Nothing
For Each oGI As GeometryIntent In oGIntents
If oGI.Geometry IsNot Nothing Then
If TypeOf oGI.Geometry Is DrawingCurve Then
Dim oDC As DrawingCurve = oGI.Geometry
Return oDC.Parent 'a DrawingView object
End If
End If
Next
Return Nothing
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Here is a different way to look at the problem:
Sub Main
Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
If IsNothing(dDoc) Then Logger.Debug("ActiveDocument type is not: " & CType(dDoc.Type, ObjectTypeEnum).ToString)
Dim PickView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View")
If IsNothing(PickView) Then Logger.Debug("Nothing was selected") : Exit Sub ' If nothing gets selected then we're done
Dim allDims As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim TrimDims As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
allDims = FillCollection(dDoc.ActiveSheet.DrawingDimensions)
PickView.Suppressed = True
TrimDims = FillCollection(dDoc.ActiveSheet.DrawingDimensions)
PickView.Suppressed = False
For Each item In TrimDims
allDims.RemoveByObject(item)
Next
Dim selectThis As HighlightSet = dDoc.CreateHighlightSet
selectThis.AddMultipleItems(allDims)
MessageBox.Show("Selected Objects", "Pause")
End Sub
Function FillCollection(DimEnumerator As DrawingDimensions) As ObjectCollection
Dim Result As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each DrawDim As DrawingDimension In DimEnumerator
Result.Add(DrawDim)
Next
Return Result
End Function
Basically, I'm collecting all dimensions before and after suppressing the desired view. Then I'm removing items that exist in both collections.
Let me know if you have any questions
Hi @J-Camper. I like your way of thinking about this task. Here is another process very similar to yours, but sort of like its opposite process. This rule suppresses all other views except the selected, puts the remaining dimensions into a collection, then un-suppresses those other views again. Both ways will likely work OK, but both with 'dirty' the document, due to the suppression changes made.
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, oPrompt)
If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Exit Sub
Dim oView As DrawingView = oObj
Dim oSheet As Sheet = oView.Parent
Dim oDDoc As DrawingDocument = oSheet.Parent
oTrans = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Suppress Views - iLogic")
For Each oOtherView As DrawingView In oSheet.DrawingViews
If oOtherView IsNot oView Then oOtherView.Suppressed = True
Next
Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
Dim oViewDimsCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDDim As DrawingDimension In oDDims : oViewDimsCol.Add(oDDim) : Next
For Each oOtherView As DrawingView In oSheet.DrawingViews : oOtherView.Suppressed = False : Next
oTrans.End
MsgBox("There are " & oViewDimsCol.Count & " dimensions in the selected view.", , "")
oDDoc.SelectSet.SelectMultiple(oViewDimsCol)
Edit: Added in the 2 lines to contain all view suppression into one Transaction in the UNDO list, per @J-Camper suggestion.
Wesley Crihfield
(Not an Autodesk Employee)
That is another way to do it. With as many suppression events as there could be with many views on a sheet, you would likely use up most of the Undo history and want to bundle the events into a single transaction. To that point, you can always abort that transaction once the objects are collected transiently, which shouldn't leave any of the suppression events behind.
Good point @J-Camper. I did not notice how many entries that made in the UNDO list, so I used your advise and updated my last code above to include 2 more lines for containing all the suppression into one Transaction.
Wesley Crihfield
(Not an Autodesk Employee)
Thank you, any code works. I will definitely use something from each
Hi,
I find this works for dimensions but not for leaders, sketched symbols and feature control frames 😞
Anyone got any ideas for getting them?
thanks,
John
Hi @johnster100. One of the only drawing annotation type objects that I've seen that actually includes a property for returning which DrawingView it is associated with is the Balloon object, which has a property called ParentView for returning a DrawingView object. In most cases, if the drawing annotation has a Leader (or at least the possibility of having a Leader), you will need to inspect the LeaderNode objects associated with its Leader, and check the LeaderNode.AttachedEntity property of each one in order to find the GeometryIntent object that you can inspect. Then, similarly to the code near the end of my example in 'Message 4' above, you can inspect the GeometryIntent, and depending on what type it is, and what type of geometry it may return, you can sometimes find the DrawingView associated with that geometry. There are multiple scenarios where that may not work out 100% of the time though, and may require more or other tactics.
Below is an example iLogic rule I created for someone else a while back for inspecting a LeaderNote to return which 'model' it references. It is not developed 100% for the possibility of other types of 'geometry' that may be returned from the GeometryIntent, but you get the idea. I do not recall which forum post I originally posted this at, or I would also include the link to that thread too.
Dim oLNote As LeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingNoteFilter, "Select a leader note to inspect.")
If oLNote Is Nothing Then Return
Dim oLeader As Inventor.Leader = oLNote.Leader
If oLeader.HasRootNode Then
Dim oRNode As LeaderNode = oLeader.RootNode
Dim oNodes As LeaderNodesEnumerator = oLeader.AllNodes
For Each oNode As LeaderNode In oNodes
If oNode.AttachedEntity Is Nothing Then Continue For
Dim oGI As GeometryIntent = oNode.AttachedEntity
Dim oGeom As Object = Nothing : Try : oGeom = oGI.Geometry : Catch : End Try
If oGeom Is Nothing Then Continue For
MsgBox("TypeName(oGeom) = " & TypeName(oGeom),,"")
If TypeOf oGeom Is DrawingCurve Then
Dim oDC As DrawingCurve = oGeom
Dim oDView As DrawingView = oDC.Parent
Dim oDViewDoc As Document = oDView.ReferencedDocumentDescriptor.ReferencedDocument
MsgBox("View Model Doc = " & oDViewDoc.FullDocumentName,,"")
Dim oMGeom As Object = oDC.ModelGeometry
MsgBox("TypeName(oMGeom) = " & TypeName(oMGeom),,"")
If TypeOf oMGeom Is Edge Then
Dim oEdge As Edge = oMGeom
Dim oNoteDoc As Document = oEdge.Parent.ComponentDefinition.Document
MsgBox("Note Model Doc = " & oNoteDoc.FullDocumentName, , "")
ElseIf TypeOf oMGeom Is Face Then
Dim oFace As Face = oMGeom
Dim oNoteDoc As Document = oFace.Parent.ComponentDefinition.Document
MsgBox("Note Model Doc = " & oNoteDoc.FullDocumentName, , "")
End If
ElseIf TypeOf oGeom Is SketchEntity Then
Dim oSE As SketchEntity = oGeom
Dim oSketch As Sketch = oSE.Parent
Dim oSketchParent As Object = oSketch.Parent
MsgBox("TypeName(oSketchParent) = " & TypeName(oSketchParent),,"")
End If
Next 'oNode
End If
Wesley Crihfield
(Not an Autodesk Employee)
Actually, there is a shorter code available for getting the DrawingView object associated with Centerline objects, Centermark objects, and GeometryIntent objects that I found a while back, which might be of interest to you, a lot of other folks here on this forum, but it requires a few entries be added into the 'Header' of the iLogic rule to make it work. It uses a special Class that is normally somewhat hidden, and is likely used internally (behind the scenes) to help with other functionality, so I can not provide a link to its documentation here.
Autodesk.FromIntent.InventorUtils.DrawingDocumentUtil.GetDrawingView()
(The line above will not work on its own, without the additional header lines being included in the rule.)
Below is an example which makes use of this seemingly built-in method, and simply 'logs' the name of the DrawingView associated with each of these types of objects it finds on the active sheet of a drawing. The GeometryIntent objects in this example are just the ones obtained from LeaderNote type objects on this sheet, because they can be obtained from many different sources.
AddReference "Autodesk.Inventor.Interop"
AddReference "Autodesk.iLogic.Core.dll"
Imports InvUtils = Autodesk.FromIntent.InventorUtils
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oCLs As Inventor.Centerlines = oSheet.Centerlines
For Each oCL As Inventor.Centerline In oCLs
Dim oCLView As Inventor.DrawingView = InvUtils.DrawingDocumentUtil.GetDrawingView(oCL)
If oCLView IsNot Nothing Then Logger.Info("Centerline Parent View = " & oCLView.Name)
Next
Dim oCMs As Inventor.Centermarks = oSheet.Centermarks
For Each oCM As Inventor.Centermark In oCMs
Dim oCMView As Inventor.DrawingView = InvUtils.DrawingDocumentUtil.GetDrawingView(oCM)
If oCMView IsNot Nothing Then Logger.Info("Centermark Parent View = " & oCMView.Name)
Next
Dim oLNotes As Inventor.LeaderNotes = oSheet.DrawingNotes.LeaderNotes
If oLNotes.Count = 0 Then Exit Sub 'or Return, or Continue For if looping sheets
For Each oLNote As Inventor.LeaderNote In oLNotes
If oLNote.Leader.HasRootNode = False Then Continue For
Dim oLastNode As Inventor.LeaderNode = oLNote.Leader.AllNodes.Item(oLNote.Leader.AllNodes.Count)
If oLastNode.AttachedEntity Is Nothing Then Continue For
Dim oGIView As Inventor.DrawingView = InvUtils.DrawingDocumentUtil.GetDrawingView(oLastNode.AttachedEntity)
If oGIView IsNot Nothing Then Logger.Info("LeaderNote Parent View = " & oGIView.Name)
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
With a quick test of manually suppressing a drawing view, it appears as though the same workflow should work with leaders, sketched symbols, and feature control frames. They all go away when suppressing the drawing view, but there could be room for error with overlapping view boundaries.
Here is the manual view suppression showing everything with attachment node within the view boundary becoming invisible when the view is suppressed:
target view, with boundary highlighted
after supression
Now there appears to be some graphics bugs when sketched symbols with hatches get "suppressed", but they do not highlight when selecting in the browser tree.
The issue I mentioned before with overlapping view boundaries is demonstrated below. There is a leader with the attachment node within both view boundaries. The view created first, "View 8" will hide the leader when suppressed, but "View 9" will not.
possible errors
I think it will work, but not as absolutely as dimensions. You should be able to modify the "FillCollection" function to a more generic enumerator object and pass in the other object enumerator types you are looking to highlight.
If you want help modifying the code, let me know.
Hi,
thanks for that. It works really well.
Is there a similar method to get the view dimensions? (if using the intent in that current function :
InvUtils.DrawingDocumentUtil.GetDrawingView(oDim.IntentOne)
then it fails if the dimension is retrieved).
thanks again,
John
Hi @johnster100. Unfortunately, I have not come across another internal/built-in method for returning the 'parent view' of a DrawingDimension type object. I have seen several different custom methods used by multiple people, on multiple forum posts, in attempts to find the best / most reliable / most efficient way of determining the connection between drawing views and drawing dimensions. I am not sure if any of them are 100% effective 100% of the time. I actually created an Inventor Ideas forum post about this issue earlier this year, to help encourage Autodesk to develop a solution into Inventor's API to help us with this widely asked about topic. Unfortunately, it still only has 1 vote, as of posting this response. Below is a link to that idea.
I see that we have had a discussion about a very similar topic before, back in June of 2021.
I even mentioned in that post that an idea should be posted about this to the Ideas forum, which I finally did after encountering a lot more similar requests on the forums. I'm a little disappointed that we have not heard of any further developments on this topic from the folks at Autodesk directly. Since they know this software inside & out, and know everything there is to know about Inventor's API and the iLogic add-in, it should be much easier for them to develop a reasonably effective solution for this situation, than it would be for us users to do. From what I have seen over the years, it depends a lot on how the dimensions were originally created, and usually comes down to inspecting the individual GeometryIntent objects associated with each dimension. Beyond that, those links mentioned in that old post (link above) are still likely the best alternatives to the 'suppression' idea.
Wesley Crihfield
(Not an Autodesk Employee)
I would like to reopen this @WCrihfield : The Function GetDimensionView works nicely, until there are dimensions between centerlines. Then TypeOF oGI.Geometry probably is Centerline (or CenterPoint?) and we need to get the view from that. But how the hell can we get the DrawingView from a Centerline??
Hi @FxRod. I actually mentioned a way to get the DrawingView that is associated with a Centermark or Centerline in Message 12 earlier in this discussion. It requires a few special lines be added into the 'Header' of the iLogic rule, to enable their recognition and functionality. The same technique can also be used on GeometryIntent objects. Since that method is defined within the iLogic resources, there is no public documentation about it that I have ever seen, so no guarantees about how effective it will be in all situations or scenarios. I have found one situation that can sometimes result in its unpredictable functionality though, and that is when the AutomatedCenterlineSettings tool is used to generate all the centermarks & centerlines. It seems like sometimes it will work with those, and other times it will not work with those. It pretty much always works on manually placed centermarks & centerlines though, as far as I have seen / heard.
DrawingSettings.AutomatedCenterlineSettings
DrawingView.GetAutomatedCenterlineSettings
DrawingSketch.GetAutomatedCenterlineSettings
DrawingView.SetAutomatedCenterlineSettings
... (there are several forum discussions in which these objects & methods are used with examples, some of which I was involved in)
I have also conversed with other forum users within other discussions about this same situation and the effectiveness (or lack thereof) of this special tool, when these objects/methods are involved.
Link to other discussion on this topic:
Wesley Crihfield
(Not an Autodesk Employee)
Attached is a text file containing the code for an updated version of an external iLogic rule that can be used for testing purposes, and it only utilizes that special iLogic tool I found for getting a DrawingView from Centerline, Centermark, or GeometryIntent type objects. This is a long, and complex rule, with several separate routines in it. One specifically for grouping DrawingDimensions with DrawingViews, one for grouping Centerlines with DrawingViews, one for grouping Centermarks with DrawingViews, and an extra one just for extracting all possible GeometryIntent objects from a DrawingDimension, because there are so many derived (more specific) sub types of DrawingDimensions, each having different properties, and some having different numbers of GeometryIntents associated with them. I could have separated out the 3 'reporting' sections of code from within the 'Main' area into separate Sub routines also, but figured that was enough complication for one rule 😉. It seemed to work OK in my preliminary tests, but I have not tested it extensively in lots of complicated situations yet. It was just designed to inspect one sheet at a time, but could be modified (and complicated) further to make is iterate through all sheets, activate them, then run this overall process on each sheet, if needed.
Wesley Crihfield
(Not an Autodesk Employee)