Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic include work axis from assembly to drawing

Anonymous

iLogic include work axis from assembly to drawing

Anonymous
Not applicable

Hello all,

Could anybody help me with edditing code: 

Dim doc As DrawingDocument = ThisDoc.Document

For Each sheet As Sheet In doc.Sheets
    For Each view As DrawingView In Sheet.DrawingViews

        Dim camera As Camera = View.Camera
        If (camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation) Then
            Continue For
        End If

        Dim refDoc = View.ReferencedDocumentDescriptor.ReferencedDocument
        Dim axis As WorkAxes = refDoc.ComponentDefinition.WorkAxes

        View.SetIncludeStatus(axis.Item(1), True)
        View.SetIncludeStatus(axis.Item(2), True)
        View.SetIncludeStatus(axis.Item(3), True)
    Next
Next

 I want include work axis from assembly to drawing - include controll ilogic rule. 

Is possible to define for what drawing view and for what axis (by name)?

 

Thanks a lot. 

0 Likes
Reply
Accepted solutions (2)
1,442 Views
12 Replies
Replies (12)

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Are you looking for something like this?

The rule lets you pick the view in the drawing and then answer yes/no if you want to include the axes...

 

Dim View As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick view")
Dim refDoc = View.ReferencedDocumentDescriptor.ReferencedDocument
Dim oAxes As WorkAxes = refDoc.ComponentDefinition.WorkAxes
For Each oAxis As WorkAxis In oAxes
	Dim oInclude As DialogResult
	oInclude = MessageBox.Show("Include " & oAxis.Name & "?", "Include Axis", _
	MessageBoxButtons.YesNo, MessageBoxIcon.Question)
	If oInclude = DialogResult.Yes Then
		View.SetIncludeStatus(oAxis, True)
	Else
		View.SetIncludeStatus(oAxis, False)
	End If
Next

Anonymous
Not applicable

Hello,

thats instring too. 

But this is not what I need. 

 

I need this: 

 

If teplomer not suprres do: 

include Work Axis5 - include / visibly.

If teplomer is suprres - Work Axis5 will be unvisibly. 

 

(in drawing will be more views, so i need to specific for what view I want to include the axis. but by name not with click set.)

I know how to do If.... and so on, but I´m fighting with VBA.

3.PNG

0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

I assume you mean if "teplomer" is invisible in the view, not suppressed?

 

Try this,

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oViewName As String = "VIEW1" 'Name of the view
Dim oView As DrawingView
For Each osView As DrawingView In oSheet.DrawingViews
	If osView.Name = oViewName
		oView = osView
		Exit For
	End If
Next
If oView Is Nothing
	MsgBox("No view found with name: " & oViewName)
	Exit Sub
End If

Dim refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition = refDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("teplomer")
Dim oAxis As WorkAxis = oDef.WorkAxes.Item("Work Axis5") 'Get axis by name
If oView.GetVisibility(oOcc) = True 'See if teplomer is visible
	oView.SetIncludeStatus(oAxis, True)
Else
	oView.SetIncludeStatus(oAxis, False)
End If

 

0 Likes

Anonymous
Not applicable

Hi, 

I want only:

Visibly axis if teplomer isn´t supress in assembly. 

I need to dimension angle of teplomer in drawing. So if I don´t have teplomer in assy, I don´t want to include axis in drawing.

Your code show me error. I don´t know why.

slo0102_0-1589795007067.png

slo0102_1-1589795083398.png

 

0 Likes

JhoelForshav
Mentor
Mentor

Were you running the code on a view based on a part when you got the error?

Could you attach the assembly? 🙂

0 Likes

Anonymous
Not applicable

Hello,

sorry my mistake. I wrote wrong view name. (first capital letter).

I little bit change your code: Visibility is controlled by linked paramter:  

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oViewName As String = "Hlavni" 'Name of the view
Dim oView As DrawingView
For Each osView As DrawingView In oSheet.DrawingViews
	If osView.Name = oViewName
		oView = osView
		Exit For
	End If
Next
If oView Is Nothing
	MsgBox("No view found with name: " & oViewName)
	Exit Sub
End If

Dim refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition = refDoc.ComponentDefinition
'Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("teplomer")
Dim oAxis As WorkAxis = oDef.WorkAxes.Item("Work Axis5") 'Get axis by name
If Parameter("ENG-000218317-P.ipt.teplomer_01") = 0.000 ul 'See if teplomer is supress
	oView.SetIncludeStatus(oAxis, False)
Else
	oView.SetIncludeStatus(oAxis, True)
End If

 

If teplomer is availabilite then  Parameter("ENG-000218317-P.ipt.teplomer_01") = 1 ul 

If teplomer is suppress then  Parameter("ENG-000218317-P.ipt.teplomer_01") = 0 ul 

 

I can´t linked True/ false parametr from base component.. 

 

But, one more problem :/. If axis get visibly, it´s "small", can I manage size of axis in code? 

 
 
 
 

6.PNG

7.PNG

 

0 Likes

JhoelForshav
Mentor
Mentor

@Anonymous 

 

Seems like you want to move the endpoint of the centerline representing the axis.

Maybe something like this?

 

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oViewName As String = "Hlavni" 'Name of the view
Dim oView As DrawingView
For Each osView As DrawingView In oSheet.DrawingViews
	If osView.Name = oViewName
		oView = osView
		Exit For
	End If
Next
If oView Is Nothing
	MsgBox("No view found with name: " & oViewName)
	Exit Sub
End If

Dim refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition = refDoc.ComponentDefinition
'Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("teplomer")
Dim oAxis As WorkAxis = oDef.WorkAxes.Item("Work Axis5") 'Get axis by name
If Parameter("ENG-000218317-P.ipt.teplomer_01") = 0.000 ul 'See if teplomer is supress
	oView.SetIncludeStatus(oAxis, False)
Else
	oView.SetIncludeStatus(oAxis, True)
End If

Dim oAxisLine As Centerline = oSheet.Centerlines.Item(oSheet.Centerlines.Count)
'Should be the last centerline, otherwise try below for loop to get it...

'For Each ocLine As Centerline In oSheet.Centerlines
'	If ocLine.ModelWorkFeature Is oAxis
'		oAxisLine = ocLine
'		Exit For
'	End If
'Next
Dim oPoint As Point2d = oAxisLine.EndPoint.Copy
Dim oVector As Vector2d = oAxisLine.Geometry.Direction.AsVector.Copy
oVector.ScaleBy(10) 'Set distance to move endpoint of line.
oPoint.TranslateBy(oVector)
oAxisLine.EndPoint = oPoint
0 Likes

Anonymous
Not applicable

Hi,

Yes you´re right. But it´s look that end point going to out of drawing view. 

slo0102_0-1589800453510.png

I tried to change vector to (-10) etc..But nothing help. Maybe change: 

oAxisLine.EndPoint.Copy 

To something like: 

oAxisLine.StartPoint.Copy ?

 

0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

 

try this instead 🙂

 

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oViewName As String = "Hlavni" 'Name of the view
Dim oView As DrawingView
For Each osView As DrawingView In oSheet.DrawingViews
	If osView.Name = oViewName
		oView = osView
		Exit For
	End If
Next
If oView Is Nothing
	MsgBox("No view found with name: " & oViewName)
	Exit Sub
End If

Dim refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition = refDoc.ComponentDefinition
'Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("teplomer")
Dim oAxis As WorkAxis = oDef.WorkAxes.Item("Work Axis5") 'Get axis by name
If Parameter("ENG-000218317-P.ipt.teplomer_01") = 0.000 ul 'See if teplomer is supress
	oView.SetIncludeStatus(oAxis, False)
Else
	oView.SetIncludeStatus(oAxis, True)
End If

Dim oAxisLine As Centerline = oSheet.Centerlines.Item(oSheet.Centerlines.Count)
'Should be the last centerline, otherwise try below for loop to get it...

'For Each ocLine As Centerline In oSheet.Centerlines
'	If ocLine.ModelWorkFeature Is oAxis
'		oAxisLine = ocLine
'		Exit For
'	End If
'Next
Dim oPoint As Point2d = oAxisLine.StartPoint.Copy
Dim oVector As Vector2d = oAxisLine.Geometry.Direction.AsVector.Copy
oVector.ScaleBy(-10)
oPoint.TranslateBy(oVector)
oAxisLine.StartPoint = oPoint
0 Likes

Anonymous
Not applicable

@JhoelForshav thank you a lot!

Where do you learn it?
I tried to find some books, but I found just one book from Autodesk, but there are just elementary knowledge.

 

0 Likes

JhoelForshav
Mentor
Mentor

@Anonymous 

 

You're welcome. I think it's best to move the scaling of the axis to within the if-statement. So you don't do all of that if the axis isn't included...

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oViewName As String = "Hlavni" 'Name of the view
Dim oView As DrawingView
For Each osView As DrawingView In oSheet.DrawingViews
	If osView.Name = oViewName
		oView = osView
		Exit For
	End If
Next
If oView Is Nothing
	MsgBox("No view found with name: " & oViewName)
	Exit Sub
End If

Dim refDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oDef As AssemblyComponentDefinition = refDoc.ComponentDefinition
'Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("teplomer")
Dim oAxis As WorkAxis = oDef.WorkAxes.Item("Work Axis5") 'Get axis by name
If Parameter("ENG-000218317-P.ipt.teplomer_01") = 0.000 ul 'See if teplomer is supress
	oView.SetIncludeStatus(oAxis, False)

Else
	oView.SetIncludeStatus(oAxis, True)
	
	Dim oAxisLine As Centerline = oSheet.Centerlines.Item(oSheet.Centerlines.Count)
	'Should be the last centerline, otherwise try below for loop to get it...

	'For Each ocLine As Centerline In oSheet.Centerlines
	'	If ocLine.ModelWorkFeature Is oAxis
	'		oAxisLine = ocLine
	'		Exit For
	'	End If
	'Next
	Dim oPoint As Point2d = oAxisLine.StartPoint.Copy
	Dim oVector As Vector2d = oAxisLine.Geometry.Direction.AsVector.Copy
	oVector.ScaleBy(-10)
	oPoint.TranslateBy(oVector)
	oAxisLine.StartPoint = oPoint
End If

I've learnt a lot from this forum or just googling stuff.

The API reference manual here is great for looking up objects and their properties, functions etc.

https://help.autodesk.com/view/INVNTOR/2020/ENU/

 

0 Likes

TecnicoPanni
Participant
Participant

Hi JhoelForshav

I'd like to include the work axis of a part in the assembly view, not of the assembly itself.

After selecting the view, is there a way to select the part I like in the selected view?

 

Thank you

 

0 Likes