AutoCAD Variable Setting Rejected

AutoCAD Variable Setting Rejected

dbrblg
Collaborator Collaborator
4,857 Views
7 Replies
Message 1 of 8

AutoCAD Variable Setting Rejected

dbrblg
Collaborator
Collaborator

I'm trying to do this in VBA/LISP:

ThisDrawing.SendCommand "(setvar " & """test""" & "(c:wd_proj_wdp_data)) "

In the command window, I get this following error:

Command: (setvar "test"(c:wd_proj_wdp_data)) ; error: AutoCAD variable setting rejected: "test" 

Initially was using the users1 variable and I had the same error.  I thought the error might have been users1 not liking something that was returned (something incompatible with a string????) so changed it and still had the same issue!!

What is the issue here?

 

Thanks

 

 

0 Likes
4,858 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant

Before trying to control commands in autocad by automation, first test it by hand, step by step.

The issue is: There isn't a variable named "TEST".

 

Command: SETVAR
Enter variable name or [?]: ?

Enter variable(s) to list <*>: TES*

No matching variables found.
Command:

 

USERS would work, but think about, it isn't saved in the system and not in the file.

Command: (setvar "USERS3" "(c:wd_proj_wdp_data)")
"(c:wd_proj_wdp_data)"

 

Check:

Command: users3

Enter new value for USERS3, or . for none <"(c:wd_proj_wdp_data)">:

 

 

We don-ät know WHY do you try to save the string "(c:wd_proj_wdp_data)"

and where should the variable/value are reachabler?

Per file, saved or just for the file session?

Per program, saved or just for the session?

 

 

Sebastian

0 Likes
Message 3 of 8

dbrblg
Collaborator
Collaborator

At the start I used USERS1 but when I got the error I tried some alternative variables to see how they differed and whether I got the same errors.  This way I could at least see whether the variable itself was at fault or what I was trying to dowith it!!  Clearly variable TEST didn't work, but I got the same error as USERS1 which does exist...

 

My initial test was:

(setvar "users1"(c:wd_proj_wdp_data))

and not:

(setvar "USERS3" "(c:wd_proj_wdp_data)")

wd_proj_wdp_data is a LISP function for AutoCAD Electrical:

AutoLISP
 (c:wd_proj_wdp_data)
Returns
List of lists (rtrn): 
(nth 0 rtrn) = wdp file name. 
(nth 1 rtrn) = count of dwgs in file. 
(nth 2 rtrn) = list of *[ ] TITLE lines (start at (nth 1)). 
(nth 3 rtrn) = list of ?[ ] values. 
(nth 4 rtrn) = list of +[ ] values. 
(nth 5 rtrn) = list of drawing names (absolute paths). 
(nth 6 rtrn) = list of dwg names (absolute paths) with sec/subsec data included. 
(nth 7 rtrn) = list of drawing names (absolute paths) with "Ref only" removed. 
(nth 8 rtrn) = internal use. 
(nth 9 rtrn) = same as (nth 5 rtrn) but forced upper case. 
(nth 10 rtrn) = sorted list of all the drawings in the project together with its subfolder data.
Description
Read active project's WDP file.

So im not trying to store the text (c:wd_proj_wdp_data) in to USERS1 but the value this function returns.

 

I only need per session store as I don't need it to persist across documents.

0 Likes
Message 4 of 8

cadffm
Consultant
Consultant

>"So im not trying to store the text (c:wd_proj_wdp_data) in to USERS1 but the value this function returns."
Ok! But users1-5 ist for STRINGs only, if it would work, you would save the list as string and not as list.


>"I only need per session store as I don't need it to persist across documents."
Let's take a look:


(c:wd_proj_wdp_data)
We don't know the definition of comamnd/function c:wd_proj_wdp_data,
so normaly we can not help, or?

_

Returns
List of lists (rtrn):

If i am right (crystal ball ON)

You start command wd_proj_wdp_data and after this, the result is bind to symbol RTRN. Is it right?
In other words: After you starts command wd_proj_wdp_data, the result is reachable by !RTRN, right?

Then.. it is quite simple:
(setq RTRN1 RTRN)
Now, the data is availbe by (nth n RTRN1)

Sebastian

0 Likes
Message 5 of 8

dbrblg
Collaborator
Collaborator

If I were to be doing this in LISP, I would do:

(setq x (c:wd_proj_wdp_data))

the lists of returned data is then available from x.  That I am ok with...

 

But the reason for me to try and assign to a user variable, is that I want to be able to access this from VBA.  So, for example, I was trying to use this:

Function ProjectDetailsTest()
    ThisDrawing.SendCommand "(setvar " & """users1""" & "(c:wd_proj_wdp_data)) "

Dim s As String s = ThisDrawing.GetVariable("users3") Debug.Print s End Function

The final goal is to retrieve data from LISP via VBA.  This is not an ideal way of doing it however I don't believe there is another easier way??? 

The issue with using my LISP example, I listed above is that I don't believe x is retrievable via VBA!!

0 Likes
Message 6 of 8

cadffm
Consultant
Consultant

You can store the information

- in external files or your registry

- as information on an object as extendet data or

- perhaps your own dictionary.

 

If you really want to read LispVariables "directly" from VBA you have to load the VisualLisp library,

but the next Problem is: VBA doesn't know what a LIST is. This objecttype is not available in VBA and in this case

it can't work

Possible to read the value from LispVariable "Test" via VisualLispTLB:

(setq Test "MyString") yes

(setq Test 44.0) yes

(setq Test '("MyFavs" 2 3 4 '(cools))) => CRASH.

 

So if you want to go this way, you have to save your RTRN Information in another structure.

 

I Prefer to write/read an external ASCII File, ini xml - simple Ascii

 

 

 

 

 

 

Sebastian

0 Likes
Message 7 of 8

john.uhden
Mentor
Mentor

I know nothing about VBA, but was wondering if he can convert the list to an array that VBA would understand.

Also, if he wants the data available per session then he could use the bulletin board... vl-bb-set and vl-bb-ref.

John F. Uhden

0 Likes
Message 8 of 8

dbrblg
Collaborator
Collaborator

@john.uhdenthat's ok not knowing about VBA as I don't know LISP 😁

 

I have managed to bash (bash being the optimum word here) a piece of lisp which outputs the list to disk.  From there my VBA can pick it up and I'm in the process of writing something to process it.

 

0 Likes