Macro with userform error

Macro with userform error

rodrigohbm
Advocate Advocate
561 Views
3 Replies
Message 1 of 4

Macro with userform error

rodrigohbm
Advocate
Advocate

Hello
I can not execute the form from   me.application
any suggestions?

regards

 

 

image.png

0 Likes
Accepted solutions (1)
562 Views
3 Replies
Replies (3)
Message 2 of 4

stever66
Advisor
Advisor

It looks like you might be mixing up the UIApplication, and the Application. 

 

If you want the UIApplication,  I think you need to use:

 

Dim uiapp As New UIApplication(Application)

 

If you want the actual application, I think you just use the "Application" keyword, or if you are in a document level macro, use the Document.Application keyword.

 

http://help.autodesk.com/view/RVT/2019/ENU/?guid=GUID-C6E0196D-918B-4131-9B64-050DBE452158

 

 

 

 

0 Likes
Message 3 of 4

Organon
Advisor
Advisor
Accepted solution

@rodrigohbm

 

Hello.

 

You're trying to get the "Application" member from the form class, that's not going to work. I don't know the best solution, but this worked for me:

 

Form:

Public Partial Class Form1
		Inherits System.Windows.Forms.Form
		
		Private m_uidoc As UIDocument

		Public Sub New(uidoc As UIDocument)			
			m_uidoc = uidoc				
			InitializeComponent()
		End Sub

		Private Sub Form1Load(sender As Object, e As EventArgs)
			
			Dim doc As Document = m_uidoc.Document

			Dim collector As New FilteredElementCollector(doc)
			collector.OfClass(GetType(ViewSheet))

			For Each vs As ViewSheet In collector
				Dim vNumber As String = vs.SheetNumber
				If vs.Name = doc.ActiveView.Name Then
					comboBox1.Items.Add(vNumber & "_" & vs.Name)
				End If
			Next
		End Sub
	End Class

ThisDocument:

Public Sub ComboBoxForm()
			Dim dialog As New Form1(Me)
			dialog.ShowDialog()

			If dialog.DialogResult = DialogResult.Cancel Then
				Return
			End If
		End Sub

P.S. I converted the code from C# to VB.NET.

 

Regards,

 

 


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
0 Likes
Message 4 of 4

rodrigohbm
Advocate
Advocate

Thank you
but I had to adjust the code
being of the following way:

 

image.png

for ThisDocument

image.png

 

regards.