VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Excel VBA execute: acadApp.ActiveDocument.SendCommand "-bedit Ankers_R"

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
pensing
3649 Views, 15 Replies

Excel VBA execute: acadApp.ActiveDocument.SendCommand "-bedit Ankers_R"

Hello!

 

I've got a block named: Ankers_R

I want to open this block via Excel VBA and the only thing I cant get it done is do the last execute enter to start.

if I put in the code:

acadApp.ActiveDocument.SendCommand "-bedit Ankers_R"

He wil execute -bedit and fill in Ankers_R on the commandline so I only have to hit enter and it goes to the editor...

I just cant figur out how to adjust this code to let it do this last enter cause when you leave a space open for enter it just sees it as text...

 

Any ideas?

Kind regards!

15 REPLIES 15
Message 2 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

try that:

acadApp.ActiveDocument.SendCommand "-bedit Ankers_R" & vbCr

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 16
pensing
in reply to: Alfred.NESWADBA

Thnx! works perfectly

 

 

Message 4 of 16
pensing
in reply to: pensing

ok, maybe it doesnt works that perfectly...

I got another problem now.

When the command is executed he opens the editor but somehow I cant see the dynamic features of a block inside that block...

When I manually open it I do see them....

What I'm trying to accomplish is that I can adjust the 2 dynamic grips so I can add a new length to them via excel.

(I've never learned to scripting things beside using scripts from others and adjust them, so I lack allot at knowing code language to find solutions...)

Any ideas?

 

Kind regards!

Message 5 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

>> What I'm trying to accomplish is that I can adjust the 2 dynamic grips

May I ask you more detailed about "adjust 2 dynamic grips"?

Do you mean you want to modify the blockdefinition ... or when the block is already inserted you want to modify the parameters "SCHAAL" and "Angle1" to resize/rotate that one blockreference?

If you mean the second one then you never have to start into blockeditor (modifying a blockdefinition would replace all blockreferences already inserted with the new modification you do in the blockeditor).

 

To access the parameters for the blockreference (the inserted object in modelspace or paperspace) then you can't do that using SendCommand. Look e.g. >>>this thread<<< or use google to search for the words >>>AutoCAD VBA GetDynamicBlockProperties<<<, that show some blogs and threads discussing the modification of parameters within a dynamic block.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 16
pensing
in reply to: Alfred.NESWADBA

Thanks Alfred for that information, it will help me allot to try to adjust the dynamic grip lengths!

But I dont want to adjust Schaal and angle.

If you open the block, you can see another block with 2 dynamics inside it.

so first I want to adjust distance1 length and after that the length of distance2.

That's what I hope to find in your useful links.

But the weird thing is, when I open the blockeditor via excel it doesnt show those 2 distances...

 

Edit,

I just notice it doenst opens the block, it opens the block and puts in the block that needs to be opent...

gonna try some things cause this I dont get...

If you know something pls reply!

Thanks in advance!

 

Edit2,

 

I've got some mistakes in my block names what I think causes the last problems...

I'll let you know if I get it fixed 🙂

 

Edit3,

 

Its fixed....

I used an old blockname to open the block so gonna try to write the codes for the dynamics...

thnx for the help so far!

Message 7 of 16
pensing
in reply to: pensing

OK, your link helped me very good cause now I managed to adjust the distances.
The thing I cant figure out here is if I put hard numbers it just works fine:

 If dybprop(i).PropertyName = "Distance1" Then
 dybprop(i).Value = 20000#

 

But if I put a string to it something like this:

Dim leng As Integer, length As String

 leng = Cells(1, 1).Value
 length = leng & "#"

 If dybprop(i).PropertyName = "Distance1" Then
 dybprop(i).Value = length

 

It doesnt understand what to do with the string, is it because a string is not a number? but I cant use an integer too because of the #... I tried this too but wont work...

dybprop(i).Value = leng & "#"

 

Maybe the solution is simple but I have not the experience and cant find it at google so far 🙂

Message 8 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

try

dybprop(i).Value = Val(length)

or

dybprop(i).Value = CDbl(length)

 

...as you can't store a string value (that might contain "IT IS TEN CM LONG") as double (as numeric value with decimal places).

So you have to convert the content of the string-variable to a double value.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 9 of 16
pensing
in reply to: Alfred.NESWADBA

Thnx Alfred!
I tried cdbl before but didnt work, but Val(length) did the trick!
Many thanks again!
Message 10 of 16
pensing
in reply to: Alfred.NESWADBA

can you help me with one last thing:

I need to save the block under a new name and the new name is a string but thats not a problem I think.

I tried via commandline but that wont work because of the inputbox it opens and searching for something simular as like changing the distances but I cant find the right stuff to get it done...

Do you have another good link or maybe the code?

Message 11 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

>> I tried via commandline but that wont work because of the inputbox it opens

What command is it that you used?

Generally: commands that raises dialogs can in most cases be started with a dash in front, so e.g.

command LAYER starts the dialog

command -LAYER starts the same command, but all is done in the command-line

For filedialogs you also can try to disable the sysvar FILEDIA, so if you try to save a drawing then you can avoid the filedialog by setting FILEDIA to 0 (and after your macro back to the value that was stored before you started your macro).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 12 of 16
pensing
in reply to: Alfred.NESWADBA

The command I uses is:

"naam" is a string

acadApp.ActiveDocument.SendCommand "bsaveas" & vbCr & naam & vbCr

but it wont fill in the name cause of the dialogbox.

-bsaveas is unknown by autocad unfortunately.

and filedia doesnt block the dialogbox from opening.

So i dont think I should save a new block via commandline.

But have no idea how to set up the a proper code that does like:

naam = Cells(row, 1).Value

block.saveas naam

 

See the attach for the full VBA.

Message 13 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

>> -bsaveas is unknown by autocad unfortunately.

>> and filedia doesnt block the dialogbox from opening

Yep, I see, try that instead:

ThisDrawing.SendCommand("(command ""_BSAVEAS"" " & naam & ")" / vbCr

The way here is to go through a lisp statement as within lisp also some dialogs are disabled, and here it seems to be the only option.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 14 of 16
pensing
in reply to: Alfred.NESWADBA

hmmm VBA cant load that line of code...

its weird that the -bsaveas doesnt excists cause the -bsave does....

Maybe you can take a look to tryout the code you think it should be...

 

Message 15 of 16
Alfred.NESWADBA
in reply to: pensing

Hi,

 

sorry, typos ;(

 

   ThisDrawing.SendCommand "(command ""_BSAVEAS""" & """" & naam & """)" & vbCr

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 16 of 16
pensing
in reply to: Alfred.NESWADBA

It works 😄
I changed it too:
acadApp.ActiveDocument.SendCommand "(command ""_BSAVEAS""" & """" & naam & """)" & vbCr

Thnx allot for the help!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost