Inventor Engineer-to-Order

Inventor Engineer-to-Order

Reply
Mentor
Lesoux
Posts: 172
Registered: ‎03-12-2012
Message 11 of 16 (291 Views)

Re: Find view object on the drawing through API.

02-04-2013 12:07 PM in reply to: Lesoux

Sometimes "getHostObject(me)" returns a document and other times a componentOccurrence.

When "getHostObject(me)" returns componentOccurrence, no issues, everything works. In other case I have this error message. How can I resolve this issue?

 

 

 

1.jpg

Win7 x64
Xeon X5647
24 Gb RAM
Quadro FX 6000

Inventor 2013
ETO 6.1, Build 140.
Employee
AlexKorzun
Posts: 113
Registered: ‎11-10-2008
Message 12 of 16 (285 Views)

Re: Find view object on the drawing through API.

02-04-2013 12:45 PM in reply to: Lesoux

Hi,

 

GetHostObject returns .Net reference to ComponentOccurence (or proxy to it) for the occurrences inside of assembly. For top level document (Root Part), the reference to the assembly document is returned.

Drawing document reference is returned for the IvDrawingDocument Intent Part.

 

I can guess from your refchain that you are attempting to call .Net in the context of some annotation on the drawing view. Depending on the view's Model, you may have to adjust proxy context first, and then figure out the geometry in IPT document.

 

If you have the small dataset that shows your problem, you may send it to ADN.

 

At least, the knowledge of the call stack will be useful at this point.

Thank you,



Alex Korzun
Autodesk Configurator 360 / Inventor ETO team
Autodesk, Inc.

Mentor
Lesoux
Posts: 172
Registered: ‎03-12-2012
Message 13 of 16 (282 Views)

Re: Find view object on the drawing through API.

02-04-2013 01:29 PM in reply to: AlexKorzun

The main goal in my case is specify entity for creating origin indicator. I want to select one part from assembly view to define all drawing curves just for this part.
If I create subassembly separately and drawing for her, GetHostObject(object as part) returns occuranceComponent.
If I create full assembly and drawing for the same subassembly, GetHostObject(object as part) returns document and I have error message that shown in the previous post.

But this error is not constant.

Win7 x64
Xeon X5647
24 Gb RAM
Quadro FX 6000

Inventor 2013
ETO 6.1, Build 140.
Employee
AlexKorzun
Posts: 113
Registered: ‎11-10-2008
Message 14 of 16 (269 Views)

Re: Find view object on the drawing through API.

02-04-2013 07:29 PM in reply to: Lesoux

Some general suggestions (not everything may be applicable, as the model is unknown to me):

 

1) Are you using Visual Studio for debugging your problem? If so, can you set a breakpoint in the suspicious place?

 

2) Disect the problem: Can you disable drawings generation? Does GetHostObject() return correct values in both asembly-only cases?

 

3) Write a workable VBA script with what you want to achieve. Then it will be easier to convert to Intent code.

 

4) Do you have a simple case that can be sent to ADN?

Thank you,



Alex Korzun
Autodesk Configurator 360 / Inventor ETO team
Autodesk, Inc.

Mentor
Lesoux
Posts: 172
Registered: ‎03-12-2012
Message 15 of 16 (263 Views)

Re: Find view object on the drawing through API.

02-05-2013 08:22 AM in reply to: AlexKorzun

This is design for creating origin point on the drawing. I didn't have any problems before. May be it's not best code.

 

<%%DisplayName("Origin Indicator"), %%Icon("Drawing-Annotation-OriginIndicator.ico")> _
Design IvOriginIndicator : deRootCustomFeatures BasePart

'------------------------------
' PARAMETERS
'------------------------------

<%%Category("Inventor"), %%Prompt("Represents the drawing view whose model contains the entity/entities to attach Ordinate Dimension to") > _
Parameter Rule view As Part = (If Parent.IsKindOf?(:IvCommonViewMixin) Then Parent Else NoValue)

<%%Category("Inventor"), %%Prompt("The part containing the entity to attach Ordinate Dimension to") > _
Parameter Rule part1 As Part = NoValue

<%%Category("Inventor"), %%Prompt("The list of entity to Ordinate Dimension, within part")> _
Parameter Rule entity1 As String = NoValue

<%%Category("Inventor"), %%Prompt("Identifies the placement point on the entity"), %%choicesType("Name"), _
%%choices(":startPoint, :endPoint, :midPoint, :circularCenterPoint, :circularLeftPoint, :circularRightPoint, :circularTopPoint, :circularBottomPoint")> _
Parameter Rule intent1 As Name = Required

<%%Category("Inventor"), %%Prompt("Sets whether the Origin Indicator should be hidden")> _
Parameter Rule originIndicatorVisible? As Boolean = True

'------------------------------
' PRIVATE RULES
'------------------------------

Rule oInvApp As Any = %%InventorApplication
Rule oActiveDoc As Any = oInvApp.ActiveDocument
Rule oActiveSheet As Any = oActiveDoc.ActiveSheet
Rule oDrawViewsSet As Any = oActiveSheet.DrawingViews

' Returns the specified view from the views on the drawing
Rule oView As Any
For i = 1 To oDrawViewsSet.Count
If oDrawViewsSet.get_Item(i).Name = viewName Then
oView = oDrawViewsSet.get_Item(i)
End If
Next
End Rule

' Returns the drawing curve within the drawing view filtered to the input model object
Rule oEdge As Any
Dim oObject As Any
If part1 <> NoValue Then
oObject = GetHostObject(part1).NativeObject ' the issue is in this row.

Else
oObject = NoValue
End If

Dim iObjQty As Integer = oView.get_DrawingCurves(oObject).Count
For i = 1 To iObjQty
Dim oEdgeP As Any = oView.get_DrawingCurves(oObject).get_Item(i).ModelGeometry
Dim oTempEdge As Any

If oEdgeP <> NoValue Then
oTempEdge = oEdgeP.NativeObject
End If

Dim oEdgeAttrSets As Any = oTempEdge.AttributeSets
Dim bEdgeAttrSetsIsUsedName? As Boolean = oEdgeAttrSets.get_NameIsUsed("Intent")
Dim oEdgeAttrSet As Any

If bEdgeAttrSetsIsUsedName? Then
oEdgeAttrSet = oEdgeAttrSets.get_Item("Intent")
Else
Exit For
End If

Dim bEdgeAttrSetIsUsedName? As Boolean = oEdgeAttrSet.get_NameIsUsed("Name")
Dim oEdgeAttr As Any

If bEdgeAttrSetIsUsedName? Then
oEdgeAttr = oEdgeAttrSet.get_Item("Name")
Else
Exit For
End If

If oEdgeAttr.Value = entity1 Then
Return oView.get_DrawingCurves(oObject).get_Item(i)
Exit For
End If
Next
End Rule

' Returns the intent point on the input geometry
Rule oIntentPoint As Any
Select(intent1)
Case :startPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kStartPointIntent)
Case :endPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kEndPointIntent)
Case :midPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kMidPointIntent)
Case :circularCenterPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kCenterPointIntent)
Case :circularRightPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kCircularLeftPointIntent)
Case :circularLeftPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kCircularRightPointIntent)
Case :circularTopPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kCircularTopPointIntent)
Case :circularBottomPoint
oIntentPoint = oActiveSheet.CreateGeometryIntent(oEdge, Inventor.PointIntentEnum.kCircularBottomPointIntent)
End Select
End Rule

' Specifies whether the origin indicator for ordinate dimensions has been created
' If the origin indicator has not been created -> Create the origin indicator -> Make the origin indicator visible/invisible
' If the origin indicator has been created -> Make the origin indicator visible/invisible
Rule Coord As Any
If Not oView.HasOriginIndicator Then
oView.CreateOriginIndicator(oIntentPoint)
oView.OriginIndicator.Visible = originIndicatorVisible?
Else
oView.OriginIndicator.Visible = originIndicatorVisible?
End If

Return oView.OriginIndicator.Intent.PointOnSheet
End Rule

'------------------------------
' CHILDREN
'------------------------------

Child OriginIndicator As :BasePart
render? = ((oView <> NoValue) And (oEdge <> NoValue) And (oIntentPoint <> NoValue) And (Coord <> NoValue))
showInModelBrowser? = False
End Child

Win7 x64
Xeon X5647
24 Gb RAM
Quadro FX 6000

Inventor 2013
ETO 6.1, Build 140.
Mentor
Lesoux
Posts: 172
Registered: ‎03-12-2012
Message 16 of 16 (258 Views)

Re: Find view object on the drawing through API.

02-05-2013 09:08 AM in reply to: Lesoux

I have fixed my issue.

Need to replace:

 

Dim oObject As Any
If part1 <> NoValue Then
oObject = GetHostObject(part1).NativeObject 

Else
oObject = NoValue
End If

 

on

 

Dim oObject As Any
Dim oCompDef As Any = oView.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition
Dim oOccur As Any = oCompDef.Occurrences

If part1 <> NoValue Then
If GetHostObject(part1).Type = Inventor.ObjectTypeEnum.kComponentOccurrenceProxyObject Then
oObject = GetHostObject(part1).NativeObject
Else
For i = 1 To oOccur.Count
If part1.occurrenceName = oOccur.get_Item(i).Name Then
oObject = oOccur.get_Item(i)
Else
oObject = NoValue
End If
Next
End If
Else
oObject = NoValue
End If

Win7 x64
Xeon X5647
24 Gb RAM
Quadro FX 6000

Inventor 2013
ETO 6.1, Build 140.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.