Jump to content

Recommended Posts

Posted (edited)

I am making a program that will allow the user to insert either one or two arrow buttons onto a work space. The button being inserted is an arrow, so it can be an up arrow or down arrow depending on what way it is rotated. See attached picture as to placing. This is basically what I want the program to end up doing.

 

Program Runs

Select Base point

Type of button?? (89, 90, 91, 92 ; colour ; material ; marking)

1 or 2 Arrows? (1 or 2 btn's)

 

Find drawings in z:\

If drawing does not exist, (princ "\nFile does not exist")

 

if entered 1 btn, then

Arrow direction (up/down)

If down, rotate btn 180 degree's

insert btn mapcar (0 +4.125 0)

 

elsif entered 2 btn's, then

insert btn mapar (0 +5.375 0)

insert btn rotate 180 degree's mapcar (0 +2.875 0)

 

Attached is my starting point code. When run, it promts the user what button style, material, colour, and marking. It stores all the information given into a variable named 'Pressel'. I want it to then locate the file in a specific drive (eg. z:\) and then insert it on

screen where the user selected. I want to expand it to suit my needs but have hit 'THE WALL' and am unsure how to proceed.

Any help is appreciated.

 

Kenter

Starting Point.lsp

Placing.jpg

Edited by Kenter
  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • Kenter

    11

  • alanjt

    1

Top Posters In This Topic

Posted Images

Posted (edited)

I can't test this as I don't have the block, but perhaps it might point you in the right direction:

 

(defun c:ARW ( / *error* vl ov f p d )
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (and ov (mapcar 'setvar vl ov))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (setq vl '("CLAYER" "CMDECHO" "OSMODE") ov (mapcar 'getvar vl))

 (if (and
       (setq f
         (findfile
           (strcat "PR"
             (apply 'strcat  
               (mapcar
                 (function
                   (lambda ( foo str init )
                     (and init (initget 1 init)) ((eval foo) str)
                   )
                 )
                 '(getkword getkword getkword)
                 '("\nSpecify Type [89/90/91/92] : "
                   "\nSpecify Material [s/B] : "
                   "\nSpecify Colour [R/W/A/G] : "
                  )
                 '("89 90 91 92" "S B" "R W A G")
               )
             )
             "-AR.dwg"
           )
         )
       )
       (setq p (getpoint "\nSpecify Insertion Point: "))
       (setq d (getangle "\nSpecify Direction: " p))

       (mapcar 'setvar (cdr vl) '(0 0))
       
       (or (tblsearch "LAYER" "PBFACE")
           (not (command "_.-layer" "_M" "PBFACE" ""))
       )
       (setvar 'CLAYER "PBFACE")
     )    
   (command "_.-insert" f "_non" (polar p (/ pi 2.) 4.125) "" "" (- (* 180. (/ d pi)) 90.))
 )

 (mapcar 'setvar vl ov)
 (princ)
)
   

Edited by Lee Mac
Posted
Command: arw

Specify Type [89/90/91/92] :

Specify Material [s/B] :

Specify Colour [R/W/A/G] :

** Error: bad argument type: stringp nil **

Posted

Haha! That'll teach me not to test it :D

 

Fixed above, thanks mate.

Posted

Hey Lee,

The interface is nice and easy. Only thing is that right after colour is selected, it stops the program. Specify Type, Material, Colour, and then just Command: I gave the exact name that the file would be called. But no promt to select insertion point. Do I have to add the directory to autocad in some way?

Posted

I tried entering this into the command promt and got nil. I was looking at the name directly and it said it cannot find it.

 

(findfile "PR90SR-1-B44")

Posted

Yeah, I wasn't sure if the block was in your support path or not..

 

Two solutions:

 

1) Add the location of the block as a support path

 

2) Specify the Directory in the LISP and 'strcat' it to prefix the filename in the first findfile call.

 

Remember to mark any mods :)

 

Lee

Posted

I forsurly will mark mods. And to add the block to the support path.... Options -> Files tab -> +Support File Seach Path ->Add

 

Or is that for only DCL files??

Posted

A support path can contain any type of file that you need to be searchable through AutoCAD :)

Posted

Is there a way to add a whole folder with sub folders as a support drive. The drawings that I am importing are on a network drive and I don't want to have to add every sub folder to all the computers in the office to be able to utilize this.

Posted

lol, I figured there was not real easy way. Thanks for all the help Lee.

 

Kenter

Posted

You could use this to add/remove support paths:

 

(defun LM:AddSupportPaths ( lst / PreferenceFiles SupportPaths )
 ;; © Lee Mac  ~  14.06.10
 ;; (AddSupportPaths '("C:\\Folder" "C:\\Folder\\Subfolder" ... )
 (vl-load-com)

 (setq SupportPaths
   (vla-get-SupportPath
     (setq PreferenceFiles
       (vla-get-files
         (vla-get-preferences
           (vlax-get-acad-object)
         )
       )
     )
   )
 )

 (vla-put-SupportPath PreferenceFiles
   (LM:lst->str
     (cons SupportPaths
       (vl-remove-if
         (function
           (lambda ( s )
             (vl-string-search s SupportPaths)
           )
         )
         lst
       )
     )
     ";"
   )
 )
 lst
)

(defun LM:RemoveSupportPaths ( lst / PreferenceFiles SupportPaths )
 ;; © Lee Mac  ~  14.06.10
 ;; (RemoveSupportPaths '("C:\\Folder" "C:\\Folder\\Subfolder" ... )
 (vl-load-com)

 (setq SupportPaths
   (vla-get-SupportPath
     (setq PreferenceFiles
       (vla-get-files
         (vla-get-preferences
           (vlax-get-acad-object)
         )
       )
     )
   )
 )

 (vla-put-SupportPath PreferenceFiles
   (LM:lst->str
     (vl-remove-if
       (function
         (lambda ( s )
           (vl-position s lst)
         )
       )
       (LM:StringParser SupportPaths ";")
     )
     ";"
   )
 )
 lst
)

(defun LM:lst->str ( lst del )
 ;; © Lee Mac  ~  14.06.10
 (if (cdr lst)
   (strcat (car lst) del (LM:lst->str (cdr lst) del))
   (car lst)
 )
)

(defun LM:StringParser ( str del )
 ;; © Lee Mac  ~  14.06.10
 (if (setq pos (vl-string-search del str))
   (cons (substr str 1 pos)
         (LM:StringParser (substr str (+ pos 1 (strlen del))) del))
   (list str)
 )
)

 

Else, let me know if you need assistance modifying my original code.

Posted

I edited the code provided by Lee Mac and wanted to make an 'if' statement so either his code, or a similar one added to the end could be run. The user would be asked to enter a quantity of parts and it gets stored as 'qty' and then if (= qty 1) then do LeeMac's code else if(= qty 2) do added code at end. Right now it will only do LeeMac's code no matter what. Any help is appreciated.

 

Kenter

 

P.s. For the single arrow, I would rather it didn't ask for any direction, rather ask if it is pointing up or down and then insert it in that direction.

Lee ARW.LSP

Posted

I'll have a look at it when I get a sec - btw: I recommend you set your format settings not to Insert Tabs, it screws with the layout when you post it in the forum :)

Posted

What do you mean 'not insert tabs'?? And how do I change that?

Posted (edited)

Perhaps something like this:

 

(defun c:ARW ( / *error* vl ov f p d qty )
 ;; © Lee Mac 2010
 
 (defun *error* ( msg )
   (and ov (mapcar 'setvar vl ov))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
   (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (setq vl '("CLAYER" "CMDECHO" "OSMODE") ov (mapcar 'getvar vl))

 (if (and
       (setq f
         (findfile
           (strcat "PR"
             (apply 'strcat
               (mapcar
                 (function
                   (lambda ( foo str init )
                     (and init (initget 1 init)) ((eval foo) str)
                   )
                 )
                 '(getkword getkword getkword)
                 '("\nSpecify Type [89/90/91/92] : "
                   "\nSpecify Material [s/B] : "
                   "\nSpecify Colour [R/W/A/G] : "
                  )
                 '("89 90 91 92" "S B" "R W A G")
               )
             )
             "-AR-B44.dwg"
           )
         )
       )
       (progn
         (while (not (< 0 (setq qty (getint "\nSpecify Number of Arrows [1/2] : ")) 3))
           (princ "\n** Please choose from 1 or 2 arrows **")
         )
         (setq p (getpoint "\nSpecify Insertion Point: "))
       )        
       
       (mapcar 'setvar (cdr vl) '(0 0))
       
       (or (tblsearch "LAYER" "PBFACE")
         (not (command "_.-layer" "_M" "PBFACE" ""))
       )
       (setvar 'CLAYER "PBFACE")
     )
   
   (if (and (= 1 qty)
            (setq d (getangle "\nSpecify Direction: " p)))
     
     (command "_.-insert" f "_non" (polar p (/ pi 2.) 4.125) "" "" (- (* 180. (/ d pi)) 90.))
     (command "_.-insert" f "_non" (polar p (/ pi 2.) 5.375) "" ""   0.
              "_.-insert" f "_non" (polar p (/ pi 2.) 2.875) "" "" 180.
     )
   )
 )

 (mapcar 'setvar vl ov)
 (princ)
)

( Again, untested )

 

Be sure to prompt for the correct data type, also, remember that the IF statement only take ONE 'then' and ONE 'else' expression, hence you need to wrapping multiple expressions using a progn to be evaluated as ONE progn statement.

 

Lee

Edited by Lee Mac
Posted
What do you mean 'not insert tabs'?? And how do I change that?

 

Your indents are all tabulated - this won't look right when posted in the forum using the [ code ] [ / code ] tags - not to mention it is annoying to have to reformat.

 

In the VLIDE, go to Tools > Environment Options > Visual LISP Format Options

Posted

Done, I was wondering how I could do that, because everytime I hit format, strange things happen. Thanks

Posted

Having the OCD-style mind that I unfortunately have, I tend to do my own formatting to how I want it...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...