vl-cmdf limitation?

Started by docsaintly, August 09, 2009, 12:42:48 AM

Previous topic - Next topic

docsaintly

Hello All. I'll try to give a synopsis and post the applicable code snippets, I'd really rather not post the entire thing as it is 1,000 lines and some of it is sensitive. Basically, I have a user interface that generates global variables, and calls a function (to make a grid of blocks) with a list of names and the directory they're in, and this grid making function calls another function that actually inserts a block based on an insertion point, directory, and filename. Each of these pieces work fine in practice, and when I step through it manually it works fine.

Any help is greatly appreciated because i'm pulling my hair out and can't figure out why this isn't working.

Code (autolisp) Select
(defun c:btnBuild_OnClicked (/ filelist counter)
(setq filelist (dcl_ListBox_GetSelectedItems lstBlocks))
(setq counter 0)
(dcl_Control_SetMinValue prgBuild 0)
(dcl_Control_SetMaxValue prgBuild (length filelist))
(getprofvars)
(blkmxgrid selectedfolder filelist)
)


Code (autolisp) Select
(defun blkmxgrid (directory blocklist / local_origin blockcount counter rowcount colcount gridcount xloc yloc)
...
(blkmx directory (nth counter blocklist) (list xloc yloc 0))



Code (autolisp) Select
(defun blkmx ( block_path block_name local_origin / block_instance block_rect
block_width block_height block_scale
l_block_ulx l_block_uly block_TUL block_UL
blockins text_instance text_width l_text_ulx
l_text_uly text_TUL text_UL XLL XLR XUR XUL)
(if (vl-cmdf "insert" (strcat block_path "\\" block_name) local_origin "1" "1" "0")
(setq block_instance (entlast))
(progn
(princ (strcat "I just failed with: " block_path "("  (vl-princ-to-string(type block_path)) ") and " block_name "("  (vl-princ-to-string(type block_name)) ") and " (vl-princ-to-string local_origin) "("  (vl-princ-to-string(type local_origin)) ")"))
(exit)
)
)
<- This piece fails, and says that i'm calling an invalid function ( I think ). I used the if statement to check the variables, and they are all fine, and when i call the (vl-cmdf "insert" .... ) function with them manually it works fine as well.

Kerry

#1
Having the exact error message would help.


Just some thoughts ..
does the path end in \\ or /   "
is the block uniformly scaled

if the block name is invalid, vl-cmdf will still return T


you could try something like ..
Code (autolisp) Select

(if (and (setq qualified_Path
(findfile (strcat block_path "\\" block_name ".dwg"))
)
(vl-cmdf "-insert" qualified_Path local_origin 1 1 0)
   )
 (setq block_instance (entlast))
)
Perfection is not optional.
My other home is TheSwamp

docsaintly

Kerry,
   Thanks for the suggestion. However, the block path is coming from a select directory dialog box, and the files are generated by

Code (autolisp) Select
(setq filelist (vl-directory-files directory "*.dwg" 1)) and then the user selects them from a listbox.

The VL-CMDF command
Code (autolisp) Select
(princ (strcat "insert " (strcat block_path "\\" block_name) (vl-princ-to-string local_origin) "1" "1" "0"))
(if (vl-cmdf "insert " (strcat block_path "\\" block_name) local_origin "1" "1" "0")
(setq block_instance (entlast))
(progn
(princ (strcat "I just failed with: " block_path "("  (vl-princ-to-string(type block_path)) ") and " block_name "("  (vl-princ-to-string(type block_name)) ") and " (vl-princ-to-string local_origin) "("  (vl-princ-to-string(type local_origin)) ")"))
(exit)
)
)
returns
"insert C:\CadTools\Project Utilities\fittings\00BA01E01.dwg(1.0 2.0
0)110I just failed with: C:\CadTools\Project Utilities\fittings(STR) and
00BA01E01.dwg(STR) and (1.0 2.0 0)(LIST); error: quit / exit abort"

When I change it to a regular command:
Code (autolisp) Select
(princ (strcat "insert " (strcat block_path "\\" block_name) (vl-princ-to-string local_origin) "1" "1" "0"))
(if (command "insert " (strcat block_path "\\" block_name) local_origin "1" "1" "0")
(setq block_instance (entlast))
(progn
(princ (strcat "I just failed with: " block_path "("  (vl-princ-to-string(type block_path)) ") and " block_name "("  (vl-princ-to-string(type block_name)) ") and " (vl-princ-to-string local_origin) "("  (vl-princ-to-string(type local_origin)) ")"))
(exit)
)
)
I get: "insert C:\CadTools\Project Utilities\fittings\00BA01E01.dwg(1.0 2.0
0)110; error: invalid AutoCAD command: nil"

The only thing I can make of this is that somehow the "insert" part is failing. I really don't know how though. I've copied the string it says it was going to use, and it points directly to a file. I've shown that it gets all of the variables it needs. I'm really baffled by why it's not working. Any more advice is greatly appreciated.

Kerry

add (vl-bt) to your failure statement and see what happens ...

Perfection is not optional.
My other home is TheSwamp

Kerry


... and remove the space in "insert "
Perfection is not optional.
My other home is TheSwamp

docsaintly

Quote from: Kerry Brown on August 09, 2009, 01:23:00 PM
add (vl-bt) to your failure statement and see what happens

Backtrace:
[0.27] (VL-BT)
[1.23] (BLKMX "C:\\CadTools\\Project Utilities\\fittings" "00BA01E01.dwg" (1.0
2.0 0))
"00BA58SHCE01_5_5.dwg" "00BA58SHCE01_5_75.dwg" "00BA58SHCE01_75.dwg"
"00BA58SHCE0201.dwg" "00BA58SHCE02_5.dwg" "00BA58SHCE02_75.dwg"
"00BA58SHCE0301.dwg" "00BA58SHCE_5_25.dwg" "00BA58SHCE_5_375.dwg"
"00BA58SHCE_5_5.dwg" "00BA58SHCE_75_25.dwg" "00BA58SHCE_75_375.dwg"
"00BA58SHCE_75_5.dwg" "00BA58SHCS01_5.dwg" "00BA58SHCS01_5_5.dwg"
"00BA58SHCS01_5_75.dwg" "00BA58SHCS01_75.dwg" "00BA58SHCS0201.dwg"
"00BA58SHCS02_5.dwg" "00BA58SHCS02_75.dwg" "00BA58SHCS0301.dwg"
"00BA58SHCS_5_25.dwg" "00BA58SHCS_5_375.dwg" "00BA58SHCS_5_5.dwg"
"00BA58SHCS_75_25.dwg" "00BA58SHCS_75_375.dwg" "00BA58SHCS_75_5.dwg"
"00BA58SHCT01_5.dwg" "00BA58SHCT01_5_5.dwg" "00BA58SHCT01_5_75.dwg"
"00BA58SHCT01_75.dwg" "00BA58SHCT0201.dwg" "00BA58SHCT02_5.dwg"
"00BA58SHCT02_75.dwg" "00BA58SHCT0301.dwg" "00BA58SHCT_5_25.dwg"
"00BA58SHCT_5_375.dwg" "00BA58SHCT_5_5.dwg" "00BA58SHCT_75_25.dwg"
"00BA58SHCT_75_375.dwg" "00BA58SHCT_75_5.dwg" "00BA60DHCE01_5.dwg"
"00BA60DHCE01_5_5.dwg" "00BA60DHCE01_5_75.dwg" "00BA60DHCE01_75.dwg"
"00BA60DHCE0201.dwg" "00BA60DHCE02_5.dwg" "00BA60DHCE02_75.dwg"
"00BA60DHCE0301.dwg" "00BA60DHCE0301_5.dwg" "00BA60DHCE0302.dwg"
"00BA60DHCE03_5.dwg" "00BA60DHCE03_75.dwg" "00BA60DHCE0401_5.dwg"
"00BA60DHCE0402.dwg" "00BA60DHCE0403.dwg" "00BA60DHCE0602.dwg"
"00BA60DHCE0603.dwg" "00BA60DHCE0604.dwg" "00BA60DHCE_5_5.dwg"
"00BA60DHCE_75_5.dwg" "00BA60DHCT01_5.dwg" "00BA60DHCT01_5_5.dwg"
"00BA60DHCT01_5_75.dwg" "00BA60DHCT01_75.dwg" "00BA60DHCT0201.dwg"
"00BA60DHCT02_5.dwg" "00BA60DHCT02_75.dwg" "00BA60DHCT0301.dwg"
"00BA60DHCT0301_5.dwg" "00BA60DHCT0302.dwg" "00BA60DHCT03_5.dwg"
"00BA60DHCT03_75.dwg" "00BA60DHCT0401.dwg" "00BA60DHCT0401_5.dwg"
"00BA60DHCT0402.dwg" "00BA60DHCT0403.dwg" "00BA60DHCT0602.dwg"))5.dwg"
"00BA52DVTT01_5.dwg" "00BA52DVTT01_5_5.dwg" "00BA52DVTT01_5_75.dwg"
"00BA52DVTT01_75.dwg" "00BA52DVTT0201.dwg" "00BA52DVTT02_5.dwg"
"00BA52DVTT02_75.dwg" "00BA52DVTT0301.dwg" "00BA52DVTT03_5.dwg"
"00BA52DVTT0401.dwg" "00BA52DVTT_5_5.dwg" "00BA52DVTT_75_5.dwg" "00BA53E01.dwg"
"00BA53E01_25.dwg" "00BA53E01_5.dwg" "00BA53E02.dwg" "00BA53E03.dwg"
"00BA53E04.dwg" "00BA53E_5.dwg" "00BA53E_75.dwg" "00BA53S01.dwg"
"00BA53S01_25.dwg" "00BA53S01_5.dwg" "00BA53S02.dwg" "00BA53S03.dwg"
"00BA53S04.dwg" "00BA53S_5.dwg" "00BA53S_75.dwg" "00BA53T01.dwg"
"00BA53T01_25.dwg" "00BA53T01_5.dwg" "00BA53T02.dwg" "00BA53T03.dwg"
"00BA53T04.dwg" "00BA53T_5.dwg" "00BA53T_75.dwg" "00BA55DHCE01_5.dwg"
"00BA55DHCE01_5_5.dwg" "00BA55DHCE01_5_75.dwg" "00BA55DHCE01_75.dwg"
"00BA55DHCE0201.dwg" "00BA55DHCE02_5.dwg" "00BA55DHCE02_75.dwg"
"00BA55DHCE0301.dwg" "00BA55DHCE03_5.dwg" "00BA55DHCE0401.dwg"
"00BA55DHCE5_5.dwg" "00BA55DHCE_75_5.dwg" "00BA55DHCT01_5.dwg"
"00BA55DHCT01_5_5.dwg" "00BA55DHCT01_5_75.dwg" "00BA55DHCT01_75.dwg"
"00BA55DHCT0201.dwg" "00BA55DHCT02_5.dwg" "00BA55DHCT02_75.dwg"
"00BA55DHCT0301.dwg" "00BA55DHCT03_5.dwg" "00BA55DHCT0401.dwg"
"00BA55DHCT_5_5.dwg" "00BA55DHCT_75_5.dwg" "00BA56SHCE01_5.dwg"
"00BA56SHCE01_5_5.dwg" "00BA56SHCE01_5_75.dwg" "00BA56SHCE01_75.dwg"
"00BA56SHCE0201.dwg" "00BA56SHCE02_5.dwg" "00BA56SHCE02_75.dwg"
"00BA56SHCE0301.dwg" "00BA56SHCE_5_5.dwg" "00BA56SHCE_75_5.dwg"
"00BA56SHCS01_5.dwg" "00BA56SHCS01_5_5.dwg" "00BA56SHCS01_5_75.dwg"
"00BA56SHCS01_75.dwg" "00BA56SHCS0201.dwg" "00BA56SHCS02_5.dwg"
"00BA56SHCS02_75.dwg" "00BA56SHCS0301.dwg" "00BA56SHCS_5_5.dwg"
"00BA56SHCS_75_5.dwg" "00BA56SHCT01_5.dwg" "00BA56SHCT01_5_5.dwg"
"00BA56SHCT01_5_75.dwg" "00BA56SHCT01_75.dwg" "00BA56SHCT0201.dwg"
"00BA56SHCT02_5.dwg" "00BA56SHCT02_75.dwg" "00BA56SHCT0301.dwg"
"00BA56SHCT_5_5.dwg" "00BA56SHCT_75_5.dwg" "00BA57DHTE01_5.dwg"
"00BA57DHTE01_5_5.dwg" "00BA57DHTE01_5_75.dwg" "00BA57DHTE01_75.dwg"
"00BA57DHTE0201.dwg" "00BA57DHTE02_5.dwg" "00BA57DHTE02_75.dwg"
"00BA57DHTE0301.dwg" "00BA57DHTE03_5.dwg" "00BA57DHTE0401.dwg"
"00BA57DHTE_5_5.dwg" "00BA57DHTE_75_5.dwg" "00BA57DHTT01_5.dwg"
"00BA57DHTT01_5_5.dwg" "00BA57DHTT01_5_75.dwg" "00BA57DHTT01_75.dwg"
"00BA57DHTT0201.dwg" "00BA57DHTT02_5.dwg" "00BA57DHTT02_75.dwg"
"00BA57DHTT0301.dwg" "00BA57DHTT03_5.dwg" "00BA57DHTT0401.dwg"
"00BA57DHTT_5_5.dwg" "00BA57DHTT_75_5.dwg" "00BA58SHCE01_5.dwg"
[3.10] (C:BTNBUILD_ONCLICKED)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 2206)

Note that the giant list of blocks is what is contained in the blocklist, the one that I am passing each one to the blkmx function. And as far as the space after insert, it was only there temporarily to see if it fixed anything (it didn't). Does this backtrace say anything useful? It looks like it's calling the command just like it should, but that for some reason autocad chooses not to reognize the insert command.

owenwengerd

#6
What is the EventInvoke property set to for the form with the btnBuild button on it? Have you considered using dcl_InsertBlock (http://www.opendcl.com/HelpFiles/index.php?page=Reference/Function/InsertBlock.htm) instead?

docsaintly

0 - Synchronous. I wasn't aware of that option, i'll give it a try and report back. Shouldn't synchronous work though?

docsaintly

Tried DCL_InsertBlock and it didn't work either. This time, I also used the exact text from the vars and it didn't work either (even though the block exists).
Although, its possible i messed up this one...
Code (autolisp) Select
(dcl_insertblock "C:\\CadTools\\Project Utilities\\fittings\\" (list
1.0 2.0 0) 0.0 "00BA01E01.dwg")


I tried it with and without a \ at the end of the directory path.

owenwengerd

No, there is no way to invoke commands synchronously from the application context.

The first argument to (dcl_InsertPath) is a filename, not a folder.

docsaintly

Success! Thank you very much Owen and Kerry! After Owen mentioned the synchronous setting, I looked closer at the documentation and saw that it specifically says you cannot use "command" with it. But since I only used synchronous because i mix it and asynchronous up, i simply changed the form/button setting. I did manage to get the dcl block insert to work, but I found it to be a bit slower than the vl-cmdf "insert". I really appreciate the help, it's a shame that a two "1"'s caused to me rip apart my code debugging and variable checking for 6 hours :\.

Thanks again.

velasquez

In OpenDCL 4.1.2.2 the function dcl_insert does work equal the dcl_insertblock in the current version? 
Does anybody have an example?

owenwengerd

Quote from: velasquez on August 10, 2009, 05:20:54 AM
In OpenDCL 4.1.2.2 the function dcl_insert does work equal the dcl_insertblock in the current version?  Does anybody have an example?

Yes, dcl_InsertBlock is the new name for the deprecated dcl_Insert function (see http://www.opendcl.com/HelpFiles/index.php?page=Reference/Function/Index.htm).