Userform different buttons - select same block multiple times

Userform different buttons - select same block multiple times

stefanveurink68AXD
Advocate Advocate
1,328 Views
5 Replies
Message 1 of 6

Userform different buttons - select same block multiple times

stefanveurink68AXD
Advocate
Advocate

So, I've got a userform with 3 buttons. When pressing first button, the user has to select a block and a private sub runs. When pressing second button, the user has to select a (the same) block and an other private sub runs. When pressing the third button, both private subs are runt. 

 

But, in both private subs the user has to select a block, so when pressing the third button, you have to select the same block two times. Which doesn't seem perfect to me. 

 

Any smart way to prevent this?

0 Likes
Accepted solutions (2)
1,329 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

Perhaps you could have one button just for selecting the block. Like in the make BLOCK dialog, you select entities to make the block with, then other controls on the form allow you to do things with the the entities. Your form needs to dimension a Private variable in the Declarations section. Then any Sub can utilize the variable. If you will always have only a single block, you could use a AcadBlockReference variable. But if you will have multiple entities, you could use an AcadSelectionSet variable.

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

Message 3 of 6

stefanveurink68AXD
Advocate
Advocate

"Perhaps you could have one button just for selecting the block. Like in the make BLOCK dialog, you select entities to make the block with, then other controls on the form allow you to do things with the the entities."

 

It's a good solution for the problem, but in my case not perfect because there are allready lots of buttons, it doesn't increase the 'easy to use for the user' (seems like other people are gonna use it). 


But anyhow i've been able to change the form a little bit and make it in such a way that you only can click the first button, in this sub the (private) blockreference gets defined, and paste all the other code in the third button after callin sub1. so in this case it's solved (but you do have same code twice, once with defining and once without) which makes me very happy. I didn't know about the private declaration so thanks a lot for our answer, i think the userform is ready now and can be tested by others. 

 

But still in the future there might be a situation in which the above isn't possible. for example when you have 3 subs in which the block needs to be selected, and the fourth sub does them all together. and for that case i'm still wondering if there isn't an better way to do this (without extra buttons). Isn't it possible somehow to pass trough a blockreference (or other variable) to an other sub, but when not passed through (if blockdefinition is empty then), definining it in the sub itself?????? I've tried to do it by "sub(blocka as blockreference)" but this gives an "procedure declaration does not match description of event or procedure having same name". 

 

Any possible options are welcome. 

 

0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

Without knowing all the details of your form/command, I only have a couple of thoughts, which may or may not work for you.

1. Make the variable in your form's Declaration section Public, then it acts like a property. Then you can start your command with a prompt to select a block, set the form's var and then show the form.

2. Your sub "sub(blocka as blockreference)" could be made so that the argument is optional, then you can call it without an argument and process according to that logic.

   Private Sub OptBlock (Optional blocka As AcadBlockReference)

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

Message 5 of 6

stefanveurink68AXD
Advocate
Advocate

Thanks, my feeling says this optional block thing is what i'm looking for, although i can't get it working yet, i still get the same error ("procedure declaration does not match description of event or procedure having same name". ) But I'll check on it when necessary... for now it's fine i guess it's what i needed. 

0 Likes
Message 6 of 6

Ed__Jobe
Mentor
Mentor

If you need more help, you're going to have to post more code and specify exactly which line throws the error.

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