Results 1 to 5 of 5

Thread: Calling up LISP routine from within another LISP

  1. #1
    Member
    Join Date
    2009-12
    Posts
    19
    Login to Give a bone
    0

    Default Calling up LISP routine from within another LISP

    Hey guys,

    I'm having an issue with a LISP routine that is made for updating titleblocks.

    Code:
    (defun C:attedit2 () 
    (setvar "cmdecho" 0)
    (setq I 0)
    (setq blkname (getstring "\nEnter the name of block to update:  "))
    (setq newatt (strcase(getstring "\nEnter new atrribute value: ")))
    (setq att1 (strcase(getstring "\nEnter the name of the attribute to change: ")))
    (setq sset (ssget "x" (list (cons 2 blkname))))
    (if (= sset nil)(setq l 0)
    (setq l (sslength sset)))
            (repeat l
            (setq stop 1)
            (setq name (ssname sset I))
                     (while (= stop 1)
                            (setq name1 (entget (entnext name)))
                            (setq ATT (cdr (assoc 2 name1)))
                            (if (= att att1)(setq go 1))
                            (setq name (cdr (assoc -1 name1)))  
                            
                            (while (= go 1)
                                    (setq d (assoc 1 name1))
                                    (setq d2 (cons 1 newatt))
                                    (setq d1 (subst d2 d name1))
                                    (entmod d1)
                                    (setq go nil)
                                    (setq stop nil)
                            )
                    )
             (setq i (1+ i))
             )
    (princ)
    (princ)
    )
    
    
    ;---------------------------------------------------------------------------
    
    
    
    
    (defun c:RevUp ()
    
    
    (AttReturn)
    
    
    
    
    ;---------------------------------------------------------------------------------------------------------
    ;Block name, Date variables and Revision date
    
    
    (setq BlockName "BW-TITLE")							;;; Block name goes here
    (setq AttBlock (ssget "x" '((0 . "insert")(2 . "BW-TITLE"))))
    
    (setq DateBlockInfo(attreturn (entget (ssname AttBlock 0)) (list "DATE01" "DATE02" "DATE03" "DATE04" "DATE05" "DATE06") 1 nil nil)) ;;; If need more dates add tag here/If tags are different change here
    (setq Date01(nth 0 DateBlockInfo))
    (setq Date02(nth 1 DateBlockInfo))
    (setq Date03(nth 2 DateBlockInfo))
    (setq Date04(nth 3 DateBlockInfo))
    (setq Date05(nth 4 DateBlockInfo))
    (setq Date06(nth 5 DateBlockInfo))						;;; Then add extra variable here
    
    
    (setq Date (rtos (getvar "CDATE") 2 6))
    (setq Yr (substr date 3 2))
    (setq Mo (substr date 5 2))
    (setq Day (substr date 7 2))
    (setq Today (strcat Day "." Mo "." Yr))
    
    ;(setq Today "01.02.10")							;;; To set date rev date manually blank out above 5 lines using ;
    
    
    ;---------------------------------------------------------------------------------------------------------
    ;If statements to set revision and revision line
    
    
    (if
    	(wcmatch Date01 "##?##?##")
    
    	(if
    		(wcmatch Date02 "##?##?##")
    		
    		(if
    			(wcmatch Date03 "##?##?##")
    
    			(if
    				(wcmatch Date04 "##?##?##")
    
    				(if
    					(wcmatch Date05 "##?##?##")
    
    					(if
    						(wcmatch Date06 "##?##?##")
    						(ERROR)		;;; If new line needed copy from "(if" to ")" below it and replace "(ERROR)"
    						(progn	(setq LineNo "06")
    							(setq Rev "F")
    						)
    					)
    
    					(progn	(setq LineNo "05")
    						(setq Rev "E")
    					)
    				)
    
    				(progn	(setq LineNo "04")
    					(setq Rev "D")
    				)
    			)
    
    			(progn	(setq LineNo "03")
    				(setq Rev "C")
    			)
    		)
    		(progn	(setq LineNo "02")
    			(setq Rev "B")
    		)
    	)
    
    	(progn	(setq LineNo "01")
    		(setq Rev "A")
    	)
    )										;;; For IFC change all Rev's to 0
    
    
    ;---------------------------------------------------------------------------------------------------------
    ;Setting tags for line that needs updating
    
    
    (setq RevLine (strcat "REV" LineNo))
    (setq DateLine (strcat "DATE" LineNo))
    (setq CheckPMLine (strcat "CHECKPM" LineNo))
    (setq CheckPDLine (strcat "CHECKPD" LineNo))
    (setq DescLine (strcat "DESCRIPTION" LineNo))
    
    
    ;---------------------------------------------------------------------------------------------------------
    ;Entering results into attribute block
    
    
    ;(COMMAND "GATTE" "B" BlockName RevLine Rev "Y")
    ;(COMMAND "GATTE" "B" BlockName DateLine Today "Y")
    ;(COMMAND "GATTE" "B" BlockName DescLine "ISSUED FOR TENDER" "Y")
    
    
    (COMMAND "AttEdit2" BlockName Rev RevLine)
    (COMMAND "AttEdit2" BlockName Today DateLine)
    (COMMAND "AttEdit2" BlockName "ISSUED FOR TENDER" DescLine)
    
    
    (princ)
    )
    If this will be irneb replying the attreturn function is the same one used in the thread "Automatic PDFing"

    The problem is that when I run it it says AttEdit2 is an unknown command, however if I run it straight from the command line i.e. type attedit2 into autocad the command runs fine. I've tried it with GATTE aswell and i get the same issue. This is the output of the LISP:

    Code:
    Command: ATTEDIT2 Unknown command "ATTEDIT2".  Press F1 for help.
    
    Command: BW-TITLE Unknown command "BW-TITLE".  Press F1 for help.
    
    Command: D Unknown command "D".  Press F1 for help.
    
    Command: REV04 Unknown command "REV04".  Press F1 for help.
    
    Command: AttEdit2 Unknown command "ATTEDIT2".  Press F1 for help.
    
    Command: BW-TITLE Unknown command "BW-TITLE".  Press F1 for help.
    
    Command: 01.02.10 Unknown command "01.02.10".  Press F1 for help.
    
    Command: DATE04 Unknown command "DATE04".  Press F1 for help.
    
    Command: AttEdit2 Unknown command "ATTEDIT2".  Press F1 for help.
    
    Command: BW-TITLE Unknown command "BW-TITLE".  Press F1 for help.
    
    Command: ISSUED FOR TENDER Unknown command "ISSUED FOR TENDER".  Press F1 for 
    help.
    
    Command: DESCRIPTION04 Unknown command "DESCRIPTION04".  Press F1 for help.
    
    
    From AutoCAD command line:
    
    Command: attedit2
    
    Enter the name of block to update:  bw-title
    
    Enter new atrribute value: 01.02.10
    
    Enter the name of the attribute to change: date04
    
    
    I'm really stuck with this one so I hope you can help!
    Cheers,
    James.

    Edit:I have since found out that you cannot call a LISP from a LISP and that you can remove the c: from c:AttEdit2 then call it using (AttEdit2). The only problem is that it leaves RevUP and goes into AttEdit2 and doesn't run the rest of RevUp.
    Last edited by Ed Jobe; 2010-02-01 at 03:23 PM. Reason: Found more info

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Calling up LISP routine from within another LISP

    Unfortunately you can't use the command function to call a command written in Lisp. You can start the lisp defun directly by issuing (c:AttEdit2). However in this case you can't send arguments to this function (either as calling arguments or using the command function).

    There are some workarounds to this:
    • You could use the ActiveX object of the current drawing (vla-get-ActiveDocument (vlax-get-acad-object)) to send a command to the command line. This basically sends keystrokes to the command line - it should work for even (defun c:*** ....) commands. Just remember that it works asynchronously, i.e. the command may still be running after sending the keystrokes. Thus your code could have errors if you rely on the command to complete before continuing.
    • A "better" solution would be to rewrite the AttEdit2, such that you have a command-line version as well as a Lisp function version. The 1st would use function pass arguments for (e.g) blkname, newatt, etc. Thus you can call it from any other lisp function and pass it the arguments. The 2nd would be a wrapper, which simply asks the user to enter these arguments - then passing them to the 1st for calculation.
    BTW, could you please surround your code in tags (without the spaces)? It makes it more readable.

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Calling up LISP routine from within another LISP

    Here's what I mean by having 2 versions of the attedit2 function:
    Code:
    (defun attedit2 (blkname newatt att1 sset / l stop name att name1 go d d2 d1 i)
      (if (= sset nil)
        (setq l 0)
        (setq l (sslength sset))
      ) ;_ end of if
      (repeat l
        (setq stop 1)
        (setq name (ssname sset I))
        (while (= stop 1)
          (setq name1 (entget (entnext name)))
          (setq ATT (cdr (assoc 2 name1)))
          (if (= att att1)
            (setq go 1)
          ) ;_ end of if
          (setq name (cdr (assoc -1 name1)))
    
          (while (= go 1)
            (setq d (assoc 1 name1))
            (setq d2 (cons 1 newatt))
            (setq d1 (subst d2 d name1))
            (entmod d1)
            (setq go nil)
            (setq stop nil)
          ) ;_ end of while
        ) ;_ end of while
        (setq i (1+ i))
      ) ;_ end of repeat
    )
    
    (defun C:attedit2 (/ blkname newatt att1 sset)
      (setvar "cmdecho" 0)
      (setq I 0)
      (setq blkname (getstring "\nEnter the name of block to update: "))
      (setq newatt (strcase (getstring "\nEnter new atrribute value: ")))
      (setq att1 (strcase (getstring "\nEnter the name of the attribute to change: ")))
      (setq sset (ssget "x" (list (cons 2 blkname))))
      (attedit2 blkname newatt att1 sset)
      (princ)
    ) ;_ end of defun
    Also note I've localized the variables in both.

  4. #4
    Woo! Hoo! my 1st post
    Join Date
    2013-06
    Posts
    1
    Login to Give a bone
    0

    Default Re: Calling up LISP routine from within another LISP

    As far as I've searched your answer is the only one concerning launching a LISP cmd from another one !
    So even 3years later.
    Thank YOU !

  5. #5
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Calling up LISP routine from within another LISP

    Thanks, but I'm sure there are other threads showing similar stuff - so I can't take all the credit. I know I learned these tricks from someone else's threads too, both the 2nd defun version as well as the sendcommand version.

Similar Threads

  1. NEED HELP WITH LISP ROUTINE - PURGE linetype lisp
    By ECASAOL350033 in forum AutoLISP
    Replies: 6
    Last Post: 2013-06-21, 01:13 AM
  2. Calling a LISP function in many drawings
    By daniel.j.wright112877 in forum AutoLISP
    Replies: 12
    Last Post: 2012-10-05, 09:48 PM
  3. Calling a script from with in a lisp
    By randy.sherwood597724 in forum AutoLISP
    Replies: 4
    Last Post: 2012-06-05, 04:13 PM
  4. Replies: 9
    Last Post: 2012-01-21, 07:58 AM
  5. Calling a lisp from within a lisp
    By LanceMcHatton in forum AutoLISP
    Replies: 10
    Last Post: 2005-10-16, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •