@patrice.vallet
This is a fairly complicated thing you are trying to do, and I would need a lot more information to be able to give you a more precise answer. I don't know how many pages are in your drawing, how many views are on each sheet, how many view need this action done to them, etc. Is the model shown in every view of every page going to be an assembly?
Here is a sample iLogic code that will attempt to search every view on every sheet of the drawing, and attempt to locate the face using the AttributeManager's FindObjects method. I also have a commented out section that you can use (for parts only) that will search for the face using NamedEntities. It only goes one layer deep under the main assembly. If you need it to go deeper into sub-assemblies, you'll have to add additional loops down through the assembly side of the code.
'Drawing
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oView As DrawingView
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oGenDims As GeneralDimensions
Dim oDim As LinearGeneralDimension
'Model
'The following 2 lines assume the model in your drawing view is always going to be an assembly.
Dim oMDoc As AssemblyDocument 'The assembly (model) being represented in the view
Dim oMDef As AssemblyComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oDocType As DocumentTypeEnum
Dim oPDoc As PartDocument
Dim oPDef As PartComponentDefinition
Dim oADoc As AssemblyDocument
Dim oADef As AssemblyComponentDefinition
Dim oAttMgr As AttributeManager
Dim oObjs As ObjectCollection
Dim oNamedEntities As NamedEntities
Dim oFace As Face
'Start Searching
For Each oSheet In oDDoc.Sheets
oGenDims = oSheet.DrawingDimensions.GeneralDimensions
For Each oView In oSheet.DrawingViews
oMDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
oMDef = oMDoc.ComponentDefinition
For Each oOcc In oMDef.Occurrences
oDocType = oOcc.DefinitionDocumentType
If oDocType = DocumentTypeEnum.kPartDocumentObject Then
oPDoc = oOcc.Definition.Document
oAttMgr = oPDoc.AttributeManager
oObjs = oAttMgr.FindObjects("DIM", "face_cadr_haut", "1")
oFace = oObjs.Item(1)
'Comment out the previous 3 lines & un-comment the next two lines to use NamedEntities instead.
'oNamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
'oFace = oNamedEntities.FindEntity("Face Name Here")
'The following line uses the view's center point as reference to place the dimension's text.
'Since I don't know what other face or entity you want to measure with this dimension,
'it also only specifies the first reference attachment of the dimension, so it will just attempt To
'measure the width of that face within the view.
'Also, it is creating a Linear dimension. Other types are available.
oDim = oGenDims.AddLinear(oTG.CreatePoint2d(oView.Center.Copy.X,oView.Center.Copy.Y + 3),oFace)
ElseIf oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
oADoc = oOcc.Definition.Document
oAttMgr = oADoc.AttributeManager
oObjs = oAttMgr.FindObjects("DIM", "face_cadr_haut", "1")
oFace = oObjs.Item(1)
oDim = oGenDims.AddLinear(oTG.CreatePoint2d(oView.Center.Copy.X,oView.Center.Copy.Y + 3),oFace)
End If
Next
Next
Next
I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.
Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.
- MessageBox, InputBox, and InputListBox Size & Format Options Click Here
- Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
- Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
- Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
- Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)