set variable as part of a path

We use different versions of the same block where the difference is the layer in which the block is drawn. The blocks with the different layers are in different folders. The path differs per block type (symbol electricity or, for example, plumbing symbol). Is it possible to save a variable and use it in the path for inserting the correct symbol?
for example: C:/pathtobasefolder/"variable"/block.dwg

Comments

  • Hi Hans

    On the commandline, in menu's, lisp files.... (?)

    (setq block-type "plumbing")

    and

    (command "._-INSERT" (strcat "C:/pathtobasefolder/" block-type "/block.dwg"))

    ... Just a thought.

  • Hans Hermans
    edited August 2019

    Hi Wiebe,

    Exactly what I was looking for, thank you!
    I immediately come to my next problem ..
    Now the intention is to have four buttons, with which I can change the path to the correct location of the block to be inserted, and the version with the chosen path gets an accent (toggle button), the other buttons must lose their accent. I thought I'd do this by linking each button to a different variable. However, my solution does not work. I think the diesel command is not correct:

    Button 1 to set the path:
    command: (setq typesymbool "-I.dwg"); (setq userr1 "1"); (setq userr2 "0")
    Diesel: $ (if, $ (=, $ (getvar, USERR1), 0) ,,!.)

    Button 2 to set the path:
    command: (setq type symbol "-I.dwg"); (setq userr1 "0"); (setq userr2 "1")
    Diesel: $ (if, $ (=, $ (getvar, USERR2), 0) ,,!.)

    Both buttons, however, retain their accent.

    The insertion of the block works perfect with your solution:
    ^c^c_-layer;s;51-53-W;;(command "-insert" (strcat "/home/hans/Bricscad/modules/kopersbegeleiding-2/53/dwg/53-bad" typesymbool));\;;

  • found it out:

    Button 1 to set the path:
    command: (setq typesymbool "-I.dwg"); (setvar "USERR1" 1); (setvar "USERR2" 0)
    Diesel: $ (if, $ (=, $ (getvar, USERR1), 0) ,,!.)

    Button 2 to set the path:
    command: (setq type symbol "-I.dwg"); (setvar "USERR1" 0); (setvar "USERR2" 1)
    Diesel: $ (if, $ (=, $ (getvar, USERR2), 0) ,,!.)

  • Wiebe van der Worp
    edited August 2019

    Good to read!

    (strcat "/home/hans/Bricscad/modules/kopersbegeleiding-2/53/dwg/53-bad" typesymbool)

    can also be written as

    (strcat (getenv "home") "/Bricscad/modules/kopersbegeleiding-2/53/dwg/53-bad" typesymbool)

    in case of corporate standardizing on Linux.

    You can put enters (;) within the command brackets by using "", the \ is for asking an insertion point, you can replace it for

    (getpoint "Specificeer een invoegpunt: ")

    because it keeps on asking till satisfied, more error resistant.

    The -layer command uses option s, option m does s(et) plus m(akes) the layer in case it does not exist and you may consider adding it to the (command ...) statement too.

    More food for thoughts :-)

  • Good to know, thanks!

  • The layer function in combination with -m option does indeed work better, now I have all the standard layers in the template but I prefer to add them if they are used.
    Is something like that also possible with the dim styles? We also work with different dim styles which are printed in different colors. I also have this in the standard template, but here too it would be easier if they were inserted the moment they were used.

  • Nice catch! Probably of use.

    By the way, you can "make" almost everything, search the net for "entmake dimstyle" for example. You'll have to dive in deep :-)

    Seen from a CAD management perspective, users purge, rename, unused things like layers and dimstyles. A way to solve this is to create a "magic button", the "if things go south press here" button. Under that button is the same code used to start and open a drawing, restoring many - not all - settings. Steal can be of use here.

    Referring to the menu line with the path (and having learned the hard way), you may consider to never use absolute paths in code, (findfile "a-file-name") searches the support file path and makes absolute paths no longer needed. Combined with, for example, a BASH script that sets the environment per user and or group, you can create flexible solutions, like (strcat (getenv "home") "/" (getenv "cad_module_x")) for setting a support file search path, search the net for "lisp set support file search path". Better than creating symlinks after 5 years (or junctions in Windows).

  • Hans Hermans
    edited August 2019

    Thank you. I will certainly go deeper into it. I use linux at home, but at my work me and my colleagues use windows. Now I have to create two CUI files with different paths after each change. On every windows PC at work the files are in the same folder (C:/Bricscad/... The contents of this folder will be updated by Nextcloud. Every change is therefore immediately implemented by everyone.

    about findfile in combination with steal. I do something wrong:
    (Steal "(findfile "basis.dwg")"'(("Dimension Styles"("KBGROEN*"))))
    is not working.. Any thoughts? :-)

  • Several expressions return several data types and want the right data type as input.

    (type expression) is your friend. Paste this on the command line...

    (type 3) (type 3.0) (type "Ola Cola") (type findfile) (type "findfile") (type (findfile "default.pgp")) (type (findfile "not_there.abc")) (setq a-string ("Ola Cola")) ("Ola Cola") (setq a-string "Ola Cola") (type (setq a-string "Ola Cola")) (type a-string) (type (read "Ola Cola")) (setq a-string (read "Ola Cola")) (type a-string)

    ... and get this as output (F2):

    (type 3)
    INT

    (type 3.0)
    REAL
    (type "Ola Cola")
    STR
    (type findfile)
    SUBR
    (type "findfile")
    STR
    (type (findfile "default.pgp"))
    STR
    (type (findfile "not_there.abc"))
    nil
    (setq a-string ("Ola Cola"))
    ; ----- Error around expression -----
    ; ("Ola Cola")
    ;
    ; error : no function definition <"Ola Cola"> ; expected FUNCTION at [eval]
    ("Ola Cola")
    ; ----- Error around expression -----
    ; ("Ola Cola")
    ;
    ; error : no function definition <"Ola Cola"> ; expected FUNCTION at [eval]
    (setq a-string "Ola Cola")
    "Ola Cola"
    (type (setq a-string "Ola Cola"))
    STR
    (type a-string)
    STR
    (type (read "Ola Cola"))
    SYM
    (setq a-string (read "Ola Cola"))
    OLA
    (type a-string)
    SYM

    Back to steal.lsp, it expects a string and a list as arguments: (steal <STR> <LIST>)

    (steal (findfile "basis.dwg") <LIST>) should work and that leaves us with <LIST>

    Lists are the base of "LISt Processing", all above are list constructions.

    What Lee does in the example is using ' as alternative for function (quote ...)

    Writing the example ( the <LIST> part) as a one liner for pasting at command line:

    (quote (("Layers" ("Layer1" "Layer2")) ("Dimension Styles" ("DimStyle*"))))

    Hoping this works...

    (steal (findfile "basis.dwg") (quote (("Dimension Styles" ("KBGROEN*")))))

  • Works, thanks! Now i have one cui file working on linux and windows!

  • With customisation it is best to avoid the "hardwiring" paths into code. Instead make use of the SRCHPATH to tell BricsCAD where to look for files.

    Regards,
    Jason Bourhill
    BricsCAD V19 Ultimate

    CAD Concepts

  • Hmm, steal works at windows, but not at linux..

    (steal (findfile "basis.dwg") (quote (("Dimension Styles" ("KBROOD*")))))
    ; ----- LISP : Call Stack -----
    ; [0]...STEAL
    ; [1].....STEAL:GETDATA <<--
    ;
    ; ----- Error around expression -----
    ; (VLAX-VLA-OBJECT->ENAME ITM)
    ; in file :
    ; /home/hans/Bricscad/modules/Support/StealV1-8.lsp
    ;
    Error: bad argument type ; expected ENTITYNAME at [vle-entget]
    :
  • @Hans Hermans said:
    Hmm, steal works at windows, but not at linux..

    (steal (findfile "basis.dwg") (quote (("Dimension Styles" ("KBROOD*")))))
    ; ----- LISP : Call Stack -----
    ; [0]...STEAL
    ; [1].....STEAL:GETDATA <<--
    ;
    ; ----- Error around expression -----
    ; (VLAX-VLA-OBJECT->ENAME ITM)
    ; in file :
    ; /home/hans/Bricscad/modules/Support/StealV1-8.lsp
    ;
    Error: bad argument type ; expected ENTITYNAME at [vle-entget]
    :

    I would expect that Lee's LISP routine is making a visual lisp (used throughout the steal app) call to something that isn't yet defined for the Mac/Linux platform. The majority of AutoCAD derived LISP routines are written for the Windows platform, you more are likely to have issues with any utilising visual lisp calls.

    Dimension styles can be defined and updated using a simple script. Attach an example. An easy way to capture dimensionstyle settings in a drawing is to go into SETTINGS on the desired drawing, then select the option to output to .csv file. This will capture all your current dimension style settings (along with other things) that you can then use to create a script. Wiebe recently produced a nice example of using a spreadsheet to create a script. See Adding GPX files to your CAD drawing

    Block definitions can be updated using -INSERT with BlockNameInDWG=BlockNameInFolder option e.g.
    (command "._-INSERT" "BlockNameInDWG=BlockNameInFolder")(command)(command)(command)

    Regards,
    Jason Bourhill
    BricsCAD V19 Ultimate
    CAD Concepts

  • Hans, you could consider filing a support request.

    Reasoning Lee uses entget, which is assumed an alias for vle-entget, see contribution of Rakesh and, hi Jason. If so, (vlax-vla-object->ename itm) returns probably something that entget doesn't understand in Linux. See line 1145. The start of a journey...

    The beauty of Jason's solution lies in the fact that you are in control, able to modify and add things, even code, for example setting tilemode 1.

  • Hans Hermans
    edited August 2019

    : I will fill in a support request.
    @ Wiebe and Jason, you are both very helpful, thank you. It is all new to me (I am a structural engineer, not a programmer) but I am starting to find my way around it.

  • I have filled in a support request. Missing functions of "steal" in the linux version will be implemented in the next version (v20).