Create button on UI and calls out userform

Create button on UI and calls out userform

tramyer7mactavish
Contributor Contributor
1,421 Views
8 Replies
Message 1 of 9

Create button on UI and calls out userform

tramyer7mactavish
Contributor
Contributor

Hi,

 

Is there a way to create a simple button on UI that calls out/show my userform?

Thank you and k.rgds,

0 Likes
Accepted solutions (1)
1,422 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

There's basically two ways.

1. Use VBARUN command for the button macro. Search this forum for VBARUN.

2. Create a lisp command wrapper for the vba and then call the command in the button macro. The advantage of this method is that you can type the command at the command line and use {Enter} to repeat the command.

 

Or are you asking how to show your form?

In a separate Sub, you create an instance of it and then use it's Show method. Then call the main sub using one of the two methods above.

 

Dim frm As myForm 
Set frm = New myForm
frm.Show()

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 9

tramyer7mactavish
Contributor
Contributor

Hi Ed,

 

I would like to create a new ribbon panel with some buttons that would be able to call/show my userform that I made on VBA manager.

is there such a way how to create a custom button on the panel ribbon and call out/show such userform?

 

thank you and kind regards,

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

Not with VBA, but C# you can. For VBA, you just have to create a ribbon panel and button macro using the CUI. Please read my tutorial that I linked to.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

Ed__Jobe
Mentor
Mentor
Accepted solution

Did my answer provide you a solution?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 9

tramyer7mactavish
Contributor
Contributor
Hi, Can you show a simple sample? a short video of this?

I'm not quite good at lisp.
0 Likes
Message 7 of 9

tramyer7mactavish
Contributor
Contributor

Hi Ed,

 

I'm a bit of confused actually.

an example module that contains

sub showForm()

 showMyForm.show

end sub


so i will just add this "showForm" on the lisp that you gave? then i can call out the command on acad is that how it works?


Btw here is your lisp


;;; get the application object
(setq *acadObj* (vlax-get-acad-object))

;; array of command name strings
(setq CommandList
(list
"showForm" "Command2"
"Command3" "Command4"
"Command5" "Command6"
)
)

;; make a defun for each command name
(foreach CommandName CommandList
(eval
(list 'defun
(read (strcat "C:" CommandName))
'()
(list 'vla-RunMacro *AcadObj* CommandName)
'(princ)
)
)
)


can you enlighten me for a bit?

0 Likes
Message 8 of 9

Ed__Jobe
Mentor
Mentor

Correct, but you will need to get rid of the other command strings you're not using. e.g. "command2".

 

You put this lisp in an mnl file named the same as your cuix, and it will load when your menu loads. Then you can click on your ribbon button or type showform at the command line.

 

P.S. When posting code in the forum, please use the code window. The button looks like </>. It keeps the formatting and color coding.

;;; get the application object
(setq *acadObj* (vlax-get-acad-object))

;; array of command name strings
(setq CommandList
  (list
    "showForm" 
  )
)

;; make a defun for each command name
(foreach CommandName CommandList
  (eval
    (list 'defun
      (read (strcat "C:" CommandName))
      '()
    (list 'vla-RunMacro *AcadObj* CommandName)
    '(princ)
    )
  )
)

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 9

Ray-Sync
Advocate
Advocate

Hola, sí hay una manera para crear un botón en autocad y puedas ejecutarlo presionando clic. Este video es ilustrativo y muy útil para tu pregunta pero está en español. Aquí te dejo el link https://youtu.be/D9TAwjslTE4

jefferson
0 Likes