Retrieve Drawing Dimension from Derived Part in Assembly

Retrieve Drawing Dimension from Derived Part in Assembly

johnster100
Collaborator Collaborator
1,484 Views
8 Replies
Message 1 of 9

Retrieve Drawing Dimension from Derived Part in Assembly

johnster100
Collaborator
Collaborator

Hi,

I'm trying to retrieve a dimension in a drawing view using API. The dimension is is within a derived part:

 

Explanation.png

 

The code I am using successfully finds the sketch in 'Pt1.ipt' but crashes when I try to create a geometry proxy of the dimension.

 

I have attached the drawing (and models) and the code can be found in the 'retrieve dim from assy rule'. I've also posted it below.

 

	'get the view
	Dim oView As Inventor.DrawingView = ActiveSheet.View("VIEW1").View

	'get the assembly document
	Dim oAssy As Inventor.AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument

	'get the assembly component definition
	Dim oAssyCompDef As Inventor.AssemblyComponentDefinition = oAssy.ComponentDefinition

	'get the first occurrence in the assembly
	Dim oCC As Inventor.ComponentOccurrence = oAssyCompDef.Occurrences.Item(1)

	'get the part document from the occurrence
	Dim oPart As Inventor.PartDocument = oCC.ReferencedDocumentDescriptor.ReferencedDocument

	'get the part component definition
	Dim oPartCompDef As Inventor.PartComponentDefinition = oPart.ComponentDefinition

	'get the collection of derived comps
	Dim oRefComps As Inventor.ReferenceComponents = oPartCompDef.ReferenceComponents

	'get the first ref doc
	Dim oRefDoc As Inventor.PartDocument = oRefComps.DerivedPartComponents.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

	Dim oDC As Inventor.DimensionConstraint = oRefDoc.AttributeManager.FindObjects(, , "TEST").Item(1)
	MsgBox(oDC.Parameter.Name) 'check we have the parameter
	 
	'create the object collection
	Dim oObjColl As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	
	Dim oDCProxy As Object
	oCC.CreateGeometryProxy(oDC, oDCProxy)

	'add the dim to the collection
	oObjColl.Add(oDCProxy)

	Dim oSheet As Inventor.Sheet = ActiveSheet.Sheet
	oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView, oObjColl)

  

Any help would be appreciated,

thanks,

John

0 Likes
Accepted solutions (2)
1,485 Views
8 Replies
Replies (8)
Message 2 of 9

yan.gauthier
Advocate
Advocate

What you are trying to do is to find a dimension from a part sketch, and then place it on a drawing view ?

 

If that is the case, what i would do is find the model geometry your dimension is attached to, and then loop through all drawing segment in the drawing view until the refered model geometry matches.

0 Likes
Message 3 of 9

johnster100
Collaborator
Collaborator

I am trying to retrieve a sketch dimension. The issue is that the part is made from a multi-body solid part (we use these a lot to create assemblies), so the sketch I want to retrieve from is in this part. In the example drawing provided I included code which can do this when the drawing view is the part, but it fails when the drawing view is of the assembly.

 

Any help is appreciated,

thanks,

John

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor

Hi @johnster100 

Try this iLogic rule as your "retrieve dim from assy"-rule.

It works for me 🙂

 

	'get the view
	Dim oView As Inventor.DrawingView = ActiveSheet.View("VIEW1").View

	'get the assembly document
	Dim oAssy As Inventor.AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument

	'get the assembly component definition
	Dim oAssyCompDef As Inventor.AssemblyComponentDefinition = oAssy.ComponentDefinition

	'get the first occurrence in the assembly
	Dim oCC As Inventor.ComponentOccurrence = oAssyCompDef.Occurrences.Item(1)

	'Get the part document From the occurrence
	Dim oPart As Inventor.PartDocument = oCC.ReferencedDocumentDescriptor.ReferencedDocument

	'get the part component definition
	Dim oPartCompDef As Inventor.PartComponentDefinition = oPart.ComponentDefinition

	'get the collection of derived comps
	Dim oRefComps As Inventor.ReferenceComponents = oPartCompDef.ReferenceComponents

	Dim oDercompProxy As Inventor.DerivedPartComponentProxy

	oCC.CreateGeometryProxy(oRefComps.DerivedPartComponents.Item(1), oDercompProxy)

	Dim oSheet As Inventor.Sheet = ActiveSheet.Sheet
	oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView, oDercompProxy.Sketches)
0 Likes
Message 5 of 9

johnster100
Collaborator
Collaborator

Hi,

that's very close to what I want, the only issue is it brings through all the model dimensions, not just the specific one I'm after (the models I will be using this on have lots of dimensions so I don't want to bring them all through).

 

Any other suggestions would be greatly appreciated,

thanks,

John

0 Likes
Message 6 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

@johnster100 

Turns out that the proxy I created in my previous reply is absolutely useless.

oDercompProxy.Sketches is actually nothing, so I didn't really pass any optional argument at all to the Retrieve function 🙂

With that said. It seems the only way to create this particular proxy is to run the Retrieve function on the entire view.

This creates our proxy and dimension, but also all the dimensions we don't want.

What we'll have to do is simply delete all the dimensions we dont want after Retrieve.

See code below:

'get the view
Dim oView As Inventor.DrawingView = ActiveSheet.View("VIEW1").View

'get the assembly document
Dim oAssy As Inventor.AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument

'get the assembly component definition
Dim oAssyCompDef As Inventor.AssemblyComponentDefinition = oAssy.ComponentDefinition

'get the first occurrence in the assembly
Dim oCC As Inventor.ComponentOccurrence = oAssyCompDef.Occurrences.Item(1)

'Get the part document From the occurrence
Dim oPart As Inventor.PartDocument = oCC.ReferencedDocumentDescriptor.ReferencedDocument

'get the part component definition
Dim oPartCompDef As Inventor.PartComponentDefinition = oPart.ComponentDefinition

'get the collection of derived comps
Dim oRefComps As Inventor.ReferenceComponents = oPartCompDef.ReferenceComponents
Dim oRefDoc As Inventor.PartDocument = oRefComps.DerivedPartComponents.Item(1).ReferencedDocumentDescriptor.ReferencedDocument

Dim oDC As Inventor.DimensionConstraint = oRefDoc.AttributeManager.FindObjects(, , "TEST").Item(1)

Dim oSheet As Inventor.Sheet = ActiveSheet.Sheet
ThisApplication.ScreenUpdating = False 'Turn off screen updating if you dont want to see unwanted dimensions for a millisecond or so...
'get them all
Dim generalDims As GeneralDimensionsEnumerator = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)
'delete the ones that isn't retrieved from a proxy with native object oDC
For Each generalDim As GeneralDimension In generalDims
	On Error Resume Next 'Just in case some dimensions aren't retrieved from proxies (no native object)
	If generalDim.RetrievedFrom.NativeObject IsNot oDC Then generalDim.Delete
Next
ThisApplication.ScreenUpdating = True 'Dont forget to turn screen updating back on

 I believe this is the only solution to the problem...

Turning off and on the screen updating while retrieving all the dimensions hides the "ugliness" of the solution 😉

Hope it works for you!

 

0 Likes
Message 7 of 9

johnster100
Collaborator
Collaborator
Accepted solution

Hi,

thanks again, that works.

 

what I've ended up doing is using:

Dim oRetrievedDims As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection 

oRetrievedDims = GeneralDimensions.GetRetrievableDimensions(oView, occ)

 

and getting the collection for all retrievable dimensions for my occurrence in a collection.

 

I then loop through checking the proxies like in your code and add the one I want. I found this slightly faster (when running on a complex model) and it prevents any dimension which were already added from being deleted.

 

thanks again,

John

0 Likes
Message 8 of 9

JhoelForshav
Mentor
Mentor

@johnster100 

That's a better solution for sure!

Glad it worked out for you 🙂

 

 

0 Likes
Message 9 of 9

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Maybe you are willing to vote this Idea in the Idea-station, that maybe brings a solution?

Derive I-properties! 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes