Pick a attribute from a component in a drawing of an assembly

Pick a attribute from a component in a drawing of an assembly

patrice.vallet
Contributor Contributor
536 Views
3 Replies
Message 1 of 4

Pick a attribute from a component in a drawing of an assembly

patrice.vallet
Contributor
Contributor

Hello,

 

I have a drawing with a assembly in, where I'm trying to put dimensions automatically.

I'm using attribute to pick up face from my assembly to attach dimension.

My problem is :

Some component are removed or added again depending of parameters, and the attribute I put on these component are broken when these components are removed and added again.

So I can't retrieved these attributes in my rules to put dimension.

 

I have thinking to put the attribute directly in my part, and use it in my drawing rule. 

I have written this code but this doesn't work.

Dim compOcc As PartDocument
compOcc = Component.InventorComponent("cadre:1")

Dim aoEdge4 As Face
oObjs = compOcc.AttributeManager.FindObjects("DIM", "face_cadr_haut", "1")
aoEdge4 = oObjs.Item(1)

 

Could you say to me if this is possible , and if yes how ?

 

Thanks

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

WCrihfield
Mentor
Mentor

Perhaps if you placed the Attribute or other identifier within the Part file or within the sub-assembly file, instead of within the ComponentOccurence within the main assembly, it would work better.  You would just have to dig a little deeper to get that Attribute or other identifier.

Also, in part files only, you can select a face, right click, and use 'Assign Name...'.  This makes it much easier to specify exactly which face you want within code environment.

When one component you're dimensioning in the drawing is removed from the assembly, is that component always replaced with another component, or not?  If it is getting replaced, you may be able to use a secondary code to assign the same Attribute to the new component, in order to maintain the functionality.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

patrice.vallet
Contributor
Contributor

@WCrihfield 

Sometime this part is replaced and sometime not. I think I can manage it by conditionnal.

I think your solution can be good. I can put the attribute directly in the part or use "assign name", but my problem is I don't know how to retrieve it in my code. Can you help me to write this piece of code ?

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

@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

EESignature

(Not an Autodesk Employee)

0 Likes