Jump to content

Recommended Posts

Posted

Greetings,

Having a problem with a routine I've been piecing together.  I can get my file copied and opened but the code ceases to work after that.  I put {{{STOPS HERE}}} to mark the spot.  How do I get around this?  I've attached the file I'm trying to edit.  Thanks.

 

(defun c:ASD (/ pt1 pt2 ss tt1 tt2)
(vl-load-com)
(vl-file-copy "C:/crg/blocks/stamps/seal-ABC.dwg" "c:/crg/19010-74-erase when done/seal-ABC.dwg")
    (vla-activate
      (vla-open (vla-get-documents (vlax-get-acad-object))
                "c:\\crg\\19010-74-erase when done\\seal-ABC.dwg"
                :vlax-false
      )
    )

;{{{ STOPS HERE}}}

(setq datestr (rtos (getvar "CDATE") 2 0))
(setq datetx (strcat "DATE SIGNED " (substr datestr 5 2) "-" (substr datestr 7 2) "-" (substr datestr 1 4)))
(setq pt1 '(-0.16260707 -0.35714304 0))    ; point list
(setq pt2 '(0.09768882 -0.46857246 0))    ; point list
(setq ss (ssget "F" (list pt1 pt2)))    ; the fence option needs a point list
(setq tt1 (entget (ssname ss 0)))    ; retrieves an object name from a selection set
(setq tt2 (cdr (assoc 1 tt1)))
(setq tt2 (subst (cons 1 datetx) (assoc 1 tt1) tt1))
(princ)
(entmod tt2)
(princ)
(COMMAND "QSAVE")
(command "close")
)
 

seal-ABC.dwg

Posted

So you are running your code in drawing A and want it to continue running in drawing B - simple answer is that you can't do that. A LISP is like a commend, and for example, you can't type "Line" in one drawing, swap to another drawing and continue drawing a line in there.

 

You might look at doing this with a script - which can be a list of LISP commands like you have but run slightly differently. Do your copy command as above and then make up your LISP from Open as a separate function, run that with the script command or with say Script Pro or Lee macs scriptwriter. This works OK if your file is closed to start with an needs opening, doesn't work well if the file to be modified is already opened.

 

-Copy File Command

- (script -scriptlisp name- )

 

should work

Posted

Sadly, that makes sense.  Thought of using a script at first but thought this could work.  Thanks a lot for the help.

  • Like 1
Posted

Worked as hoped.  Turned out to be the same thing, only different.

 

 

<lsp routine>

(defun c:ASD (/ pt1 pt2 ss tt1 tt2)
(vl-load-com)
(vl-file-copy "C:/crg/blocks/stamps/seal-ABC.dwg" "c:/crg/19010-74-erase when done/seal-ABC.dwg")

(command "script" "c:/crg/scripts/asd.scr")

);defun

 

<script file>

_open
"c:/crg/19010-74-erase when done/seal-ABC.dwg"
(setq datestr (rtos (getvar "CDATE") 2 0))
(setq datetx (strcat "DATE SIGNED " (substr datestr 5 2) "-" (substr datestr 7 2) "-" (substr datestr 1 4)))
(setq pt1 '(-0.16260707 -0.35714304 0))
(setq pt2 '(0.09768882 -0.46857246 0))
(setq ss (ssget "F" (list pt1 pt2)))
(setq tt1 (entget (ssname ss 0)))
(setq tt2 (cdr (assoc 1 tt1)))
(setq tt2 (subst (cons 1 datetx) (assoc 1 tt1) tt1))
(entmod tt2)
QSAVE
close
 

Thanks again, Steven P

  • Like 1
Posted

maybe just do your stuff and then use saveas?

Posted

rlx, the code posted above took care of it...thanks.  

Posted

Be careful with file names that have spaces in them, depending on how the lisp is constructed the code can stop at the 1st space in the filename, insert can be a command that can be affected.

Posted (edited)

what is bugging me is that you can get text contents with vlax get property 'contents but vlax put property contents doesn't work. it only seems to work with vanilla lisp to change text value for arc aligned text 😨

 

p.s. content problem solved but OP is happy with solution from Steven P so guess no need any more to post my version.

Edited by rlx
Posted
12 hours ago, rlx said:

so guess no need any more to post my version.

@rlx  as for to know as it is , please upload your version.

thanks 

Posted (edited)

yeah but no but yeah but... nah , no problem 🙂  its a little bit more complex than just a simple script but (with in the back of my mind I usually have to deal with thousands of drawings) I thought: well lets make something that can easily be pimped / upgrade for other purposes.

 

anywayz , the code :

 

things can be more compact obviously but that wasn't my goal. Just to do a 'change text' on a drawing not currently loaded , simular to (but simpler than)  Lee's batch text editor. It doesn't select a text by fence but by going through all objects until it finds an arcalignedtext that contains "*signed*".

 

;;; https://www.cadtutor.net/forum/topic/77282-code-for-editing-drawing-after-opening/

(defun c:ASD ( / ActApp ActDoc docs dwgs OldErr dbx fol sub dwg d)
  (ASD_Init) (ASD_DoMyStuff) (ASD_Exit) (princ) 
)

(defun ASD_Init () (vl-load-com) (setq OldErr *error*)
  (defun *error* (s) (princ "\n*error* : " (vl-princ-to-string s)) (ASD_Exit) (setq *error* OldErr)(princ))
  (setq ActApp (vlax-get-acad-object) ActDoc (vla-get-activedocument ActApp) docs (vla-get-documents ActApp))
  (vlax-for x docs (if (= 1 (vlax-variant-value (vla-getvariable x "DWGTITLED")))(setq dwgs (cons (cons (vla-get-fullname x) x) dwgs))))
)

(defun ASD_Exit ()
  (mapcar '(lambda (x) (if (and (= 'vla-object (type (eval x)))(not (vlax-object-released-p (eval x))))
    (progn (vlax-release-object (eval x)) (set (quote x) nil)))) (list 'dbx-doc 'dbx 'docs 'ActDoc 'ActApp))(gc))

(defun ASD_DoMyStuff ( / 2d sign dbx-doc fol sub dwg s)
  (setq 2d (rtos (getvar "CDATE") 2 0) sign (strcat "DATE SIGNED " (substr 2d 5 2) "-" (substr 2d 7 2) "-" (substr 2d 1 4)))
  ;;; (vl-file-copy "c:/crg/blocks/stamps/seal-ABC.dwg" "c:/crg/19010-74-erase when done/seal-ABC.dwg")
  (setq fol "c:/crg/blocks/stamps/" sub "19010-74-erase when done/" dwg "seal-ABC.dwg")
  (vl-file-copy (strcat fol dwg) (setq dwg (strcat fol sub dwg)))
  (if (setq dbx-doc (dbx_open dwg))
    (vlax-for b (vla-get-blocks dbx-doc)
      (vlax-for o b (if (and (eq (vla-get-objectname o) "AcDbArcAlignedText") (vlax-property-available-p o 'contents t)
        (setq s (vlax-get-property o 'contents)) (wcmatch (strcase s t) "*signed*"))(vlax-put-property o 'contents sign)))))
  (vl-catch-all-apply 'vla-saveas (list dbx-doc dwg))
  (princ)
)

;--- Odbx ------------------------------------------------- Begin Odbx Section --------------------------------------------------- Odbx ---

(defun InitObjectDBX ()
  (setq dbx (vl-catch-all-apply 'vla-getinterfaceobject (list ActApp (dbx_ver))))
    (if (or (null dbx) (vl-catch-all-error-p dbx))(progn (princ "\nObjectDbx not available") (setq dbx nil))) dbx)

(defun dbx_open ( $dwg / doc)
  (cond ((or (void $dwg) (not (setq $dwg (findfile $dwg)))) (princ "\nInvalid drawing")(setq doc nil))
	((not (or dbx (InitObjectDBX))) (princ "\nObjectDbx not available")(setq doc nil))
        ((setq doc (cdr (assoc $dwg dwgs))))
	((vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx (findfile $dwg))))
	 (princ "\nUnable to open drawing.")(setq doc nil))
	(t (setq doc dbx)))
  doc
)

(defun odbx_close ( %doc )
  (if (and (= 'vla-object (type %doc))(not (vlax-object-released-p %doc)))(progn (vlax-release-object %doc))(setq %doc nil)))

(defun dbx_ver ( / v)
  (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v)))))

; checks if variable is bound and if it is a string it's not empty
(defun void (x) (or (eq x nil) (and (listp x)(not (vl-consp x))) (and (eq 'STR (type x)) (eq "" (vl-string-trim " \t\r\n" x)))))

;--- Odbx -------------------------------------------------- End Odbx Section ---------------------------------------------------- Odbx ---

 

🐉

Edited by rlx

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...