Jump to content

Avoiding Copy and Paste to secure clipboard data progress!


Recommended Posts

Posted (edited)

Need someone to get this tool to crash for a test and get me to find solution.

Had this previously using no entmake or trans but seems to work now.

 

(defun c:4x  (/ *error* pt1 pt2 ss  )
(princ (strcat "\n 45"(chr 186)"/135"(chr 186)" 3D.XLines <!pp>"))

  (defun *error* ( msg )
     (setvar 'cmdecho 0)    
   (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
      (if msg (prompt (strcat "\n" msg)))
        (setvar 'cursorsize 100)    ;; reset to my prefer
     (setvar 'cmdecho 1)    
 (princ)
  )
    
  (setvar 'cursorsize 1)
  
  (entmakex ;;                  <LM
   '(
        (000 . "LAYER")
        (100 . "AcDbSymbolTableRecord")
        (100 . "AcDbLayerTableRecord")
        (002 . "XLINE")      ;; Layer Name
        (070 .  0)           ;; Layer Status     (bit-coded)
        (006 . "Continuous") ;; Layer Linetype   (must be loaded)
        (062 .  252)          ;; Layer Colour     (1-255)
        (290 .  0)           ;; Non-Plot Flag    (0=Plot, 1=NoPlot)
        (370 . -3)           ;; Layer Lineweight (-3=Default)
    )
) 

   (defun zPoint ( / exv) ;; 3d point mfg
      (setq pt1 (trans pt1 1 0))
      (setq exv (trans (list 0 0 1) 1 0 T))
      (entmakex (list (cons 0 "POINT")
      (cons 10 pt1)
      (cons 210 exv)))
    )

   (defun cdd ()
      (princ "\n")
        (princ 
          (setq pp                               ;;  make/prints coords & paste usable
                  (strcat 
                     (rtos (car pt1) 2 4) ","        ;; 'p' -- vertex from pgm /\ getpoint,...
                     (rtos (cadr pt1) 2 4) ","
                     (rtos (caddr pt1) 2 4) 
                    )
                 )
        ) 
   (princ " cucs ");;    ;   (entmakex (list (cons 0 "POINT") (cons 10 pt))) ;; clean point 
                 
  (setenv "pp" pp) ;; crash saved coords
 )

;;// -----------------------------------------------------------------------------------------------------------
      ;; Get the initial placement point
(while (setq pt1 (getpoint "\nSpecify Point for XLines: "))
(setvar 'cmdecho 0)
    (progn
      ;; Create a new empty selection set
      (setq ss (ssadd))
      
      ;; Create horizontal xline and add to selection set
      (command "_.xline" "_a" 45 pt1 "")
      (command "chprop" "_L" "" "la" "XLINE" "") ;; make xline grey
      (ssadd (entlast) ss)
      
      ;; Create vertical xline and add to selection set
      (command "_.xline" "_a" 135 pt1 "")
       (command "chprop" "_L" "" "la" "XLINE" "") ;; make xline grey
     (ssadd (entlast) ss)
     (cdd) ;; post coords
    (zPoint) ;; point at 'pick.point
    )
(setvar 'cmdecho 1) 
  ) ;; end of while
  
  (princ)
)

 

Edited by ScottMC
forgot variable..
Posted
3 hours ago, ScottMC said:
(command "chprop" "_L" "" "la" "XLINE" "") ;; make xline grey

The character (_) is missing in these lines.

(command "_chprop" "_L" "" "_la" "XLINE" "") ;; make xline grey

Maybe that's the problem.

Posted (edited)
12 hours ago, ScottMC said:

Need someone to get this tool to crash for a test and get me to find solution.

Had this previously using no entmake or trans but seems to work now.

@ScottMC I don't see any functional problems with it, other than as Nikon said, you should use the "_." before commands, even though they are not strictly necessary.

 

FYI - The "." (dot) ensures the actual AutoCAD command is used, in case it has been redefined, and the "_" (underscore) allows the command and any options within it to be used in any localized language version of AutoCAD. Example in your routine: (command "_.chprop" "_L" "" "_la" "XLINE" "")

 

Additionally:

1) You should also reset your "cursorsize" variable at the end of the routine: (setvar 'cursorsize 100)

2) You are resetting an undo mark in your error routine, and you never included a starting undo mark, i.e. (vla-startundomark (vla-get-activedocument (vlax-get-acad-object))) at the beginning of the routine.

3) Your routine or file should have (vl-load-com) if you use the Visual LISP ActiveX functions in #2 above.

4) You don't need a (progn ...) statement within a (while) loop. (Added)

 

That being said. I cannot properly test the purpose of the "zpoint" function without knowing in what context you are using it, i.e. a sample drawing situation to test with? Otherwise I don't really understand your purpose for it.

Edited by pkenewell
  • Agree 1
Posted

@ScottMC P.S. - I see now what the "zpoint" function intent is; for using (entmake) to create the points. I tried it out in a 3D drawing file, changing the current UCS, and it seems to work. fine.

Posted

Suggestions received, posted and updated. As with the coords, the point is a reference entity. Thanks

 

(defun c:4x  (/ *error* pt1 pt2 ss  )
(princ (strcat "\n 45"(chr 186)"/135"(chr 186)" 3D.XLines <!pp>"))
;; ai: https://www.google.com/search?q=saving+2+lines+selection%2C+autolisp&client=firefox-b-1-e&hs=AnK&sca_esv=3c4c5acec5573df9&biw=1198&bih=593&ei=JazVaZ2GN-3fp84P46_CyAM&ved=0ahUKEwjdrJWQit2TAxXt78kDHeOXEDkQ4dUDCBE&oq=saving+2+lines+selection%2C+autolisp&gs_lp=Egxnd3Mtd2l6LXNlcnAiInNhdmluZyAyIGxpbmVzIHNlbGVjdGlvbiwgYXV0b2xpc3AyBRAAGO8FMgUQABjvBTIFEAAY7wUyCBAAGKIEGIkFSKOCAVDmIlj5PHABeACQAQCYAakBoAHdCKoBAzEuN7gBDMgBAPgBAZgCCaACqAvCAg4QABiABBiwAxiGAxiKBcICCBAAGLADGO8FwgILEAAYsAMYogQYiQXCAgoQIRigARjDBBgKwgIIECEYoAEYwwSYAwCIBgGQBgqSBwUxLjYuMqAHwSSyBwUwLjYuMrgHzwrCBwczLTYuMi4xyAfBAYAIAA&sclient=gws-wiz-serp

(vl-load-com)

  (defun *error* ( msg )
     (setvar 'cmdecho 0)    
   (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
      (if msg (prompt (strcat "\n" msg)))
        (setvar 'cursorsize 100)    ;; reset to my prefer
     (setvar 'cmdecho 1)    
 (princ)
  )
    (vla-startundomark (vla-get-activedocument (vlax-get-acad-object))) ;; 
  (setvar 'cursorsize 1)
  
  (entmakex ;;                  <LM
   '(
        (000 . "LAYER")
        (100 . "AcDbSymbolTableRecord")
        (100 . "AcDbLayerTableRecord")
        (002 . "XLINE")      ;; Layer Name
        (070 .  0)           ;; Layer Status     (bit-coded)
        (006 . "Continuous") ;; Layer Linetype   (must be loaded)
        (062 .  252)          ;; Layer Colour     (1-255)
        (290 .  0)           ;; Non-Plot Flag    (0=Plot, 1=NoPlot)
        (370 . -3)           ;; Layer Lineweight (-3=Default)
    )
) 

   (defun zPoint ( / exv) ;; 3d point at xline _mid (not on 'xline layer)
      (setq pt1 (trans pt1 1 0))
      (setq exv (trans (list 0 0 1) 1 0 T))
      (entmakex (list (cons 0 "POINT")
      (cons 10 pt1)
      (cons 210 exv)))
    )

   (defun cdd ()
      (princ "\n")
        (princ 
          (setq pp                               ;;  make/prints coords & paste usable
                  (strcat 
                     (rtos (car pt1) 2 4) ","        ;; 'p' -- vertex from \/ getpoint
                     (rtos (cadr pt1) 2 4) ","
                     (rtos (caddr pt1) 2 4) 
                    )
                 )
        ) 
   (princ " cucs ");; 
                 
  (setenv "pp" pp) ;; crash saved coords in reg
 )

;;// -----------------------------------------------------------------------------------------------------------
      ;; Get the initial placement point ;; 
(while (setq pt1 (getpoint "\nSpecify Point for XLines: "))
 (setvar 'cmdecho 0)
   (progn
      ;; Create a new 'usable' empty selection set
      (setq ss (ssadd)) ;; Initialize an empty set:
      
      ;; Create horizontal xline and add to selection set
      (command "_.xline" "_a" 45 pt1 "")
      (command "_.chprop" "_L" "" "_la" "XLINE" "") ;; make xline grey
      (ssadd (entlast) ss) ;; adds 'xline to empty 'ss selection set
      
      ;; Create vertical xline and add to selection set
      (command "_.xline" "_a" 135 pt1 "")
       (command "_.chprop" "_L" "" "_la" "XLINE" "") ;; make xline grey
     (ssadd (entlast) ss)  ;; adds another 'xline to 'ss selection set 
     (cdd) ;; post coords of 'pick.point
    (zPoint) ;; point at 'pick.point
    )
   (setvar 'cursorsize 100)    ;; reset to my prefer
(setvar 'cmdecho 1) 
  ) ;; end of while
(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
(*error* nil)
  (princ)
)

 

  • Like 1
Posted

A couple more comments:

 

Collected the defuns together at the top of the routine - easier to spot them that way

Used vl-princ-to-string for the coordinates to string, looses the ',' though but the reverse shouldn't need that

Added a check that the layer exists before making it new (could be an error)

Reset system variables to as they were (eg cmdecho_old) rather than specifying a value

Just tidied up the indenting a touch - my ADHD - and added some annotations for closing brackets

Do you need to use the selection set for anything else (ss)

In the entmakex point, do you need to set 210 ?

 

 

 

(defun c:4x  (/ *error* pt1 ss  )
  (vl-load-com) 
  (defun *error* ( msg )
    (setvar 'cmdecho 0)    
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if msg
      (prompt (strcat "\n" msg))
    )
    (setvar 'cursorsize Cursor_Old)  ;; reset
    (setvar 'cmdecho CmdEcho_Old)    ;; reset
    (princ)
  ) ; end *errror*

  (defun zPoint ( pt1 / exv) ;; 3d point mfg ;; added pt1, usually better to specify
    (setq pt1 (trans pt1 1 0))
    (setq exv (trans (list 0 0 1) 1 0 T))
    (entmakex (list
      (cons 0 "POINT")
      (cons 10 pt1)
      (cons 210 exv) ;; do you need to use 210?
    )) ; end entmakex, end list
  ) ; end zpoint

  (defun cdd ( pt1 / pp)
    (princ "\n")
    (setq pp (vl-princ-to-string pt1))
    (princ pp)
;    (princ 
;      (setq pp
;        (strcat 
;          (rtos (car pt1) 2 4) ","        ;; 'p' -- vertex from pgm /\ getpoint,...
;          (rtos (cadr pt1) 2 4) ","
;          (rtos (caddr pt1) 2 4) 
;        ) ; end strcat
;      ) ; end setq
;    ) ; end princ
    (princ " cucs ");;    ;   (entmakex (list (cons 0 "POINT") (cons 10 pt))) ;; clean point 
    (setenv "pp" pp) ;; crash saved coords
  ) ; end defun cdd
  
  (vla-startundomark (vla-get-activedocument (vlax-get-acad-object))) ;; Start Undo

  (if (tblsearch "LAYER" "XLINE")
    (princ "\nLayer Exists") ;; Layer exist. Do nothing
    (entmakex '(
      (000 . "LAYER")
      (100 . "AcDbSymbolTableRecord")
      (100 . "AcDbLayerTableRecord")
      (002 . "XLINE")      ;; Layer Name
      (070 .  0)           ;; Layer Status     (bit-coded)
      (006 . "Continuous") ;; Layer Linetype   (must be loaded)
      (062 .  252)         ;; Layer Colour     (1-255)
      (290 .  0)           ;; Non-Plot Flag    (0=Plot, 1=NoPlot)
      (370 . -3)           ;; Layer Lineweight (-3=Default)
    )) ; end list, end entmakex
  ) end if layer

  (princ (strcat "\n 45"(chr 186)"/135"(chr 186)" 3D.XLines <!pp>"))
  (setq Cursor_Old (getvar 'cursorsize))
  (setvar 'cursorsize 1)

;; Get the initial placement point
  (setq CmdEcho_Old (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (while (setq pt1 (getpoint "\nSpecify Point for XLines: "))
    (progn
      ;; Create a new empty selection set
      (setq ss (ssadd)) ;; do you need this if it is a local variable - or is there more code later?
      ;; Create horizontal xline and add to selection set
      (command "_.xline" "_a" 45 pt1 "")
      (command "_.chprop" "_L" "" "_la" "XLINE" "") ;; make xline grey
      (ssadd (entlast) ss) ;; likewise, do you need this
      ;; Create vertical xline and add to selection set
      (command "_.xline" "_a" 135 pt1 "")
      (command "_.chprop" "_L" "" "_la" "XLINE" "") ;; make xline grey
      (ssadd (entlast) ss) ;; and this
      (cdd pt1) ;; post coords
      (zPoint pt1) ;; point at 'pick.point
    ) ; end progn
  ) ;; end of while

;;--reset variables--;;
  (setvar 'cmdecho CmdEcho_Old)
  (setvar 'cursorsize Cursor_Old)
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object))) ;; End Undo
  (princ) ; exit quietly
)

 

  • Agree 1

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