Automatic addition of dimensions in the drawing

Automatic addition of dimensions in the drawing

doma-zieman
Participant Participant
756 Views
5 Replies
Message 1 of 6

Automatic addition of dimensions in the drawing

doma-zieman
Participant
Participant
In the assembly drawing.
In the components (parts) the planes are described.
I want the rule to create a dimension between these planes.
Error displays all the time.


Sub Main() '[ Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets oSheets = oDoc.Sheets Dim oSheet As Sheet oSheets.Item(1).Activate oSheet = oDoc.ActiveSheet Dim nazwa As String = ThisDoc.FileName(False) 'without extension ZN = Len(nazwa) znn = ZN - 4 pref = Left(nazwa, ZN - 4) Dim oView1 As DrawingView oView1 = oSheet.DrawingViews.Item(1) ' 'Readys code for Creation of reference points for dimension placement Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oPt1 As Point2d oPt1 = oTG.CreatePoint2d(oView1.Left + (oView1.Width / 3), oView1.Top - oView1.Height - 1) ' setting the component name Dim C0 As String C0 = pref & "-004:1" Dim C1 As String C1 = pref & "-005:2" Dim C2 As String C2 = pref & "-005:3" Dim viewModelDoc = ActiveSheet.View("WIDOK10").ModelDocument For Each oOcc00 As ComponentOccurrence In viewModelDoc.ComponentDefinition.Occurrences If oOcc00.Name = C0 Then For Each oOcc1 As ComponentOccurrence In viewModelDoc.ComponentDefinition.Occurrences 'MessageBox.Show(oOcc00.Name, "Title") If oOcc1.Name = C1 Then 'MessageBox.Show("Title", "Title") 'MessageBox.Show("C1", "Title") PlaceDIMinPart(oView1, oSheet, "Wym2", "WymN", oPt1, oOcc00, oOcc1) Exit For End If Next Exit For End If Next '] End Sub Private Function PlaceDIMinPart(oView As DrawingView, oSheet As Sheet, SFaceName As String, EFaceName As String, InsertPT As Point2d, oComp1 As ComponentOccurrence, oComp2 As ComponentOccurrence) '[ Dim aoFace1 As Inventor.FaceProxy aoFace1 = FindFace(oView, oSheet, SFaceName, oComp2) Dim aoFace2 As Inventor.FaceProxy aoFace2 = FindFace(oView, oSheet, EFaceName, oComp1) Dim oDrawCurves1 As Inventor.DrawingCurvesEnumerator oDrawCurves1 = oView.DrawingCurves(aoFace1) Dim aoFace2Edge1 As DrawingCurve aoFace2Edge1 = oDrawCurves1.Item(1) oDrawCurves2 = oView.DrawingCurves(aoFace2) Dim aoFace2Edge2 As DrawingCurve aoFace2Edge2 = oDrawCurves2.Item(1) '[ Dim startPoint2 As Point2d Dim endPoint2 As Point2d startPoint2 = aoFace2Edge2.StartPoint endPoint2 = aoFace2Edge2.EndPoint Dim startPoint1 As Point2d Dim endPoint1 As Point2d startPoint1 = aoFace2Edge1.StartPoint endPoint1 = aoFace2Edge1.EndPoint '] '[ 'Readys code for creation of general dimensions Dim oGeneralDims As GeneralDimensions oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions '] Dim oDim2 As GeneralDimension oDim2 = oGeneralDims.AddLinear(InsertPT, endPoint1 , endPoint2 , kHorizontalDimensionType) oDim2.Precision = 0 Dim oDim2Att As AttributeSet oDim2Att = oDim2.AttributeSets.Add("auto") '] End Function
Function FindFace(oView As DrawingView, oSheet As Sheet, FaceName As String, oComp As ComponentOccurrence) As Inventor.FaceProxy '[ Dim oAssemblyDoc As AssemblyDocument oAssemblyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oPartDoc As PartDocument = oComp.Definition.Document Dim oObjs As ObjectCollection oObjs = oPartDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", FaceName)
If oObjs.Count > 0 Then Dim oFace As Inventor.Face oFace = oObjs.Item(1) Dim oFaceProxy As Inventor.FaceProxy Call oComp.CreateGeometryProxy(oFace, oFaceProxy) FindFace = oFaceProxy End If '] End Function Error in underlined line:
EN:
The COM model object of type 'System.__ComObject' cannot be cast to the interface type 'Inventor.GeometryIntent'. This operation failed because a call to the QueryInterface method for the COM model component to retrieve an interface with IID identifier '{56B990B9-D25A-436F-A652-1D21EC739C57}' failed due to the following error: Such interface is not supported. (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). PL: Nie można rzutować obiektu modelu COM typu 'System.__ComObject' na typ interfejsu 'Inventor.GeometryIntent'. Ta operacja nie powiodła się, ponieważ wywołanie metody QueryInterface dla składnika modelu COM w celu uzyskania interfejsu o identyfikatorze IID '{56B990B9-D25A-436F-A652-1D21EC739C57}' nie powiodło się z powodu następującego błędu: Taki interfejs nie jest obsługiwany. (Wyjątek od HRESULT: 0x80004002 (E_NOINTERFACE)).
Accepted solutions (1)
757 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

I see your error is in the code?

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
Message 3 of 6

doma-zieman
Participant
Participant
oDim2 = oGeneralDims.AddLinear(InsertPT, endPoint1 , endPoint2 , kHorizontalDimensionType)

 

oPt1 = oTG.CreatePoint2d(oView1.Left + (oView1.Width / 3), oView1.Top - oView1.Height - 1)

oView1 - is in place, it is on this sheet

X=20,4 Y=14,21

 

Dim endPoint2 As Point2d

X=10,4 Y=16,665

Dim endPoint1 As Point2d

X=30,4 Y=16,665

 

I do not know which ingredient cannot be dropped? Why can't it be dumped?

 

0 Likes
Message 4 of 6

duke
Enthusiast
Enthusiast

When you say you want to dimension between two "planes", are you referring to work planes? Are these planes visible on your drawing? Drawing dimensions can only be placed between, or on, visible lines in the drawing. Work planes will very often cause errors because of how they are evaluated. Are there 2 faces that you can use instead? Faces are more reliable, and I can provide the code you would need to find named faces.

0 Likes
Message 5 of 6

doma-zieman
Participant
Participant

No, they are called the faces of the element (appendix). They are visible.

0 Likes
Message 6 of 6

duke
Enthusiast
Enthusiast
Accepted solution

Looking at your code, I believe your error may be that you didn't actually create a face proxy, you just referenced a face and attempted to apply the faceProxy type. Below is a code snippet that I use when I am automating dimensions. You see that I actually create and pass a face proxy.

 

Dim oComp as ComponentOccurrence
oComp = oModelDoc.ComponentDefinition.Occurrences(i)

'Locate the "FrontFace" face of the part
Dim FrontFace As Face = namedEntities.FindEntity("FrontFace") 'Create a geometry proxy to reference for the face oComp.CreateGeometryProxy(FrontFace, oSketchProxy)
'Locate the associated curve in the drawing view Dim oCurve As DrawingCurvesEnumerator = oBaseView.DrawingCurves(oSketchProxy) Dim oIntent As GeometryIntent oIntent = oSheet.CreateGeometryIntent(oCurve.Item(1))

  

0 Likes