Running lisp in one open dwg file that changes another open dwg file

Running lisp in one open dwg file that changes another open dwg file

nick.seman
Advocate Advocate
510 Views
3 Replies
Message 1 of 4

Running lisp in one open dwg file that changes another open dwg file

nick.seman
Advocate
Advocate

I have two dwg files open "A" and "B".  I am running a lisp in "A"

 

Can anyone explain to me why in the following snip, the line gets drawn in "B" but the coordinate system gets set in "A" instead of "B"?

 

Thanks;

Nick

 

(vlax-for Doc (vla-get-Documents (vlax-get-acad-object))
   (if (= (vla-get-name Doc) "B.dwg")
      (progn
         (vla-activate Doc)
         (vlax-put-property (vlax-get-property zonesettings 'coordinatesystem) 'cscode "PA83-NF")
         (vla-AddLine
            (vla-get-ModelSpace Doc)
            (vlax-3d-point '(0 0 0))
            (vlax-3d-point '(5 5 0))

         );AddLine
      );progn
   );if
);vlax

 

0 Likes
Accepted solutions (1)
511 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor
Accepted solution

That’s because vlax-put-property function has no reference to doc but the vla-add line function does reference doc 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 4

LDShaw
Collaborator
Collaborator

Following. 
I have not had much luck switching active documents. If there is a way to reliably do this I would like to understand it better. 
From my understanding AutoLISP does not always automatically switch the context to the new active document especially when modifying properties or adding objects it may still affect the initially active drawing, even after switching focus. 


0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

This is very limited testing but seems to work.

 

 

; simple jump to another dwg that is open
; By AlanH Nov 2023

(defun c:dodwg ( / acdocs lst x ans but cnt)
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq cnt (vlax-get acdocs 'count))

(setq lst '())
(setq x 0)
(repeat cnt
  (setq lst (cons (vlax-get (vla-item acdocs x) 'name) lst))
  (setq x (1+ x))
)
(setq lst (reverse lst))

(If (< cnt 16)
  (progn
   (if (not AH:Butts)(load "Multi radio buttons.lsp"))
   (setq lst (cons "Please choose " lst))
   (setq ans (ah:butts 1 "V"  lst))
   (setq dbx (vla-item acdocs (- but 1)))
  )
  (alert "to many dwg's open will skip ")
)

(vla-addline (vla-get-modelspace dbx)
   (vlax-3D-point '(0.0 0.0))
   (vlax-3D-point '(30.0 50.0))
)

(vlax-release-object dbx)
(princ)
)
(c:dodwg)

 

0 Likes