Numbering For the Stairs or Disc Stack

Numbering For the Stairs or Disc Stack

JadhavP1
Contributor Contributor
928 Views
6 Replies
Message 1 of 7

Numbering For the Stairs or Disc Stack

JadhavP1
Contributor
Contributor

I wish to do numbering on the .idw file which has a base view for zigzag stairs. I want to number the stairs as (#1, #2 , #3.....so on. Is there any way by which we can number the stairs on a click. A message prompt at start for the numbering start from value & later on, on every clicks it shall be incremental text appear on the sheet.

0 Likes
Accepted solutions (2)
929 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @JadhavP1 

You can add this iLogic rule to the drawing document and run it.

It asks you to give the start number and after that you can just klick anywhere on the drawing to place annotations.

Exit the function with esc-key 🙂

 

Public Sub Main()
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oStartVal As Integer = InputBox("Start value", "Set start value", 1)
	
	Dim getPoint As New clsGetPoint
	Dim pnt As Point2d

	Do
		pnt = getPoint.GetDrawingPoint("Click the desired location", MouseButtonEnum.kLeftMouseButton)
		If Not pnt Is Nothing Then
			oSheet.DrawingNotes.GeneralNotes.AddFitted(pnt, "#" & oStartVal)
			oStartVal += 1
		End If
	Loop While Not pnt Is Nothing
End Sub
Class clsGetPoint
	Private WithEvents m_interaction As InteractionEvents
	Private WithEvents m_mouse As MouseEvents
	Private m_position As Point2d
	Private m_button As MouseButtonEnum
	Private m_continue As Boolean
	

	Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
		Dim ThisApplication As Inventor.Application = GetObject(Nothing,"Inventor.Application")
		m_position = Nothing
		m_button = button
		m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
		m_mouse = m_interaction.MouseEvents

		m_interaction.StatusBarText = Prompt

		m_interaction.Start

		m_continue = True
		Do
			ThisApplication.UserInterfaceManager.DoEvents
		Loop While m_continue

		m_interaction.Stop

		GetDrawingPoint = m_position
	End Function


	Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles m_mouse.OnMouseClick
	Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
		If button = m_button Then
			m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
		End If

		m_continue = False
	End Sub
End Class
Message 3 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @JadhavP1 

The code I posted earlier gets stuck in a loop!

Even though it at first seems like inventor behaves as normal after you hit esc, some functionalities are blocked due to a lingering handler.

 

This code however should work 🙂

I make sure pnt is actually set to nothing when you terminate the interaction with esc and then i do a bit of clean-up setting the events to nothing.

 

Public Sub Main()
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oStartVal As Integer = InputBox("Start value", "Set start value", 1)

	Dim getPoint As New clsGetPoint
	Dim pnt As Point2d

	Do
		pnt = getPoint.GetDrawingPoint("Click the desired location", MouseButtonEnum.kLeftMouseButton)
		If Not pnt Is Nothing Then
			oSheet.DrawingNotes.GeneralNotes.AddFitted(pnt, "#" & oStartVal)
			oStartVal += 1
		End If
	Loop While Not pnt Is Nothing
	getPoint.CleanUp
End Sub
Class clsGetPoint
	Private WithEvents m_interaction As InteractionEvents
	Private WithEvents m_mouse As MouseEvents
	Private m_position As Point2d
	Private m_button As MouseButtonEnum
	Private m_continue As Boolean


	Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
		Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
		m_position = Nothing
		m_button = button
		m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
		m_mouse = m_interaction.MouseEvents

		m_interaction.StatusBarText = Prompt

		m_interaction.Start

		m_continue = True
		Do
			ThisApplication.UserInterfaceManager.DoEvents
		Loop While m_continue

		m_interaction.Stop

		GetDrawingPoint = m_position
	End Function


	Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles m_mouse.OnMouseClick
		Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
		If button = m_button Then
			m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
		End If

		m_continue = False
	End Sub
	
	Private Sub oInteraction_OnTerminate() Handles m_interaction.OnTerminate
        m_continue = False
    End Sub
	Public Sub CleanUp
		m_mouse = Nothing
        m_interaction = Nothing
	End Sub
End Class

I apologise if you had to restart inventor due to testing my previous code.

Message 4 of 7

JadhavP1
Contributor
Contributor

Hello jhoel.forshav                      
Thanks This worked perfectly, but an we have an option to set the text alignment at the start where we are providing input for the starting number. I mean whether to have text clockwise 90 or ACCW 90 (vertical or horizontal).

0 Likes
Message 5 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @JadhavP1

I'm glad it worked for you!

Try this to also set the rotation 🙂

 

Public Sub Main()
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	Dim oStartVal As Integer = InputBox("Start value", "Set start value", 1)
	Dim oRotation As Double = InputBox("Set CCW rotation:", "Set rotation", 90)
	Dim getPoint As New clsGetPoint
	Dim pnt As Point2d

	Do
		pnt = getPoint.GetDrawingPoint("Click the desired location", MouseButtonEnum.kLeftMouseButton)
		If Not pnt Is Nothing Then
			Dim oNote As GeneralNote = oSheet.DrawingNotes.GeneralNotes.AddFitted(pnt, "#" & oStartVal)
			oNote.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
			oNote.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
			oNote.Position = pnt
			oNote.Rotation = oRotation * PI/180
			oStartVal += 1
		End If
	Loop While Not pnt Is Nothing
	getPoint.CleanUp
End Sub
Class clsGetPoint
	Private WithEvents m_interaction As InteractionEvents
	Private WithEvents m_mouse As MouseEvents
	Private m_position As Point2d
	Private m_button As MouseButtonEnum
	Private m_continue As Boolean


	Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
		Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
		m_position = Nothing
		m_button = button
		m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
		m_mouse = m_interaction.MouseEvents

		m_interaction.StatusBarText = Prompt

		m_interaction.Start

		m_continue = True
		Do
			ThisApplication.UserInterfaceManager.DoEvents
		Loop While m_continue

		m_interaction.Stop

		GetDrawingPoint = m_position
	End Function


	Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles m_mouse.OnMouseClick
		Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
		If button = m_button Then
			m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
		End If

		m_continue = False
	End Sub

	Private Sub oInteraction_OnTerminate() Handles m_interaction.OnTerminate
		m_continue = False
	End Sub
	Public Sub CleanUp
		m_mouse = Nothing
		m_interaction = Nothing
	End Sub
End Class
0 Likes
Message 6 of 7

JadhavP1
Contributor
Contributor

Perfect Code as required. Thank You 🙂

Message 7 of 7

adamXL2U2
Observer
Observer

I don't know what's going on with my inventor but the code gives an error on line 34 when I enter the session to use the left mouse click... do I have to change some configuration within the inventor? Or the code may be out of date?

0 Likes