Problem with importing CAD commands with space between characters from EXCEL VBA

Problem with importing CAD commands with space between characters from EXCEL VBA

Anonymous
Not applicable
1,468 Views
5 Replies
Message 1 of 6

Problem with importing CAD commands with space between characters from EXCEL VBA

Anonymous
Not applicable

Hi,

 

I have a problem with inserting commands from VBA to CAD file. The problem is because of the space between characters used. For instance, for the command of "Cannoscale" in Imperial drawings, I need to type 1/8" = 1'-0" in excel file but when importing from excel to CAD, the vba thinks those spaces are like "enter" command and the program does not work properly. Does anyone have any idea for solving this issue?

 

 

Thanks,

0 Likes
1,469 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant

I dont think you have problems in Acad with blanks, but you have problems to send the right string.

 

Your string result in Acad should be 1/4" = 1'-0", your sendcommand(?) interpret " as start or end of a string,

you have to quote them for the right result. It is a VBA string handling issue.

 

"_.CANNOSCALE 1/4" & Chr(34) " = 1'-0" & Chr(34) & vbCr
or perhaps
"_.CANNOSCALE 1/4"" = 1'-0"" & vbCr
or
"_.CANNOSCALE 1/4"" = 1'-0"" "
(sorry, i am not so familar with vba, bu the point is not the blank.. 😉

 

Try it yourself with a simple message box, the string you send should display exactly: 1/4" = 1'-0"

Sebastian

0 Likes
Message 3 of 6

Ed__Jobe
Mentor
Mentor

Its a mixture of vba formatting and lisp escape characters. This should work.


Sub CAset()
    ThisDrawing.SetVariable "cannoscale", "1/4\" & Chr(34) & " = 1" & Chr(39) & "-0\"""
End Sub

If you had an extra xl column, you could store the vba formatting required for the SetVariable argument and just retrieve it from there.

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 4 of 6

Anonymous
Not applicable

Hi all,

 

I thought it might be useful for others but I ended up writing a lisp routine like this to define imperial scales and using that I solved my problem: (In my vba I just used the new commands (e.g., CAN34)).

 

(defun c:CAN11 () (setvar "cannoscale" "1\" = 1'-0\""))
(defun c:CAN34 () (setvar "cannoscale" "3/4\" = 1'-0\""))
(defun c:CAN12 () (setvar "cannoscale" "1/2\" = 1'-0\""))
(defun c:CAN38 () (setvar "cannoscale" "3/8\" = 1'-0\""))
(defun c:CAN14 () (setvar "cannoscale" "1/4\" = 1'-0\""))
(defun c:CAN316 () (setvar "cannoscale" "3/16\" = 1'-0\""))
(defun c:CAN18 () (setvar "cannoscale" "1/8\" = 1'-0\""))
(defun c:CAN332 () (setvar "cannoscale" "3/32\" = 1'-0\""))
(defun c:CAN116 () (setvar "cannoscale" "1/16\" = 1'-0\""))
(defun c:CAN132 () (setvar "cannoscale" "1/32\" = 1'-0\""))
(defun c:CAN164 () (setvar "cannoscale" "1/64\" = 1'-0\""))
(defun c:CAN1128 () (setvar "cannoscale" "1/128\" = 1'-0\""))

 

(defun C:Reset_Cannoscale_List_Imperial ( / xpt)
(command "-scalelistedit"
"reset"
"yes"
"exit")
(command "cannoscale" "1\" = 1'-0\"") ; Allows AutoCAD to maintain alphabetical order ;);
(setq xpt (getvar "EXPERT"))
(setvar "EXPERT" 5)
(command "-scalelistedit"
"delete" "*"
"add" "1\" = 1'-0\"" "1:12"
"add" "3/4\" = 1'-0\"" "1:16"
"add" "1/2\" = 1'-0\"" "1:24"
"add" "3/8\" = 1'-0\"" "1:32"
"add" "1/4\" = 1'-0\"" "1:48"
"add" "3/16\" = 1'-0\"" "1:64"
"add" "1/8\" = 1'-0\"" "1:96"
"add" "3/32\" = 1'-0\"" "1:128"
"add" "1/16\" = 1'-0\"" "1:192"
"add" "1/32\" = 1'-0\"" "1:384"
"add" "1/64\" = 1'-0\"" "1:768"
"add" "1/128\" = 1'-0\"" "1:1536"
"Exit")
(setvar "EXPERT" xpt)
(command "CANNOSCALE" "1/8\" = 1'-0\"") ; Change this to one of the scales in above code
(princ)
)

0 Likes
Message 5 of 6

cadffm
Consultant
Consultant

only about C:Reset_Cannoscale_List_Imperial:

 

Maybe I'm misinterpreting the lines, but why do not you set your default scalelist in AutoCAD to this list?
Then would a -scalelistedit reset suffice?

Sebastian

0 Likes
Message 6 of 6

Anonymous
Not applicable

True, that part could be ignored by simply changing the list in the template CAD file. I just decided to do it via lisp.

0 Likes