sublimation Posted July 11, 2019 Posted July 11, 2019 I can't figure out why when I manually enter the command it doesn't cause a regeneration of the model, but when I run my code, it causes it twice. (defun C:PJ () (get_CurrentState) (setvar "CMDECHO" 0) (setvar "PEDITACCEPT" 1) (COMMAND ".PEDIT" PAUSE "JOIN" "ALL" "" "") (cond ((= (cdr (assoc 70 (entget (entlast)))) 1) (princ (strcat "\nPolyline: CLOSED Vertices: " (itoa (cdr (assoc 90 (entget (entlast))))) "\n"))) ((= (cdr (assoc 70 (entget (entlast)))) 0) (princ "\nPolyline: OPEN\n")) ) (set_CurrentState) (princ) ) It's not super critical that it happens, but it is certainly annoying. Any insight would be much appreciated. Quote
Lee Mac Posted July 11, 2019 Posted July 11, 2019 What are the definitions for these two functions? get_CurrentState / set_CurrentState Quote
sublimation Posted July 11, 2019 Author Posted July 11, 2019 2 minutes ago, Lee Mac said: What are the definitions for these two functions? get_CurrentState / set_CurrentState Lee, Here is the rest of the code. (setq gbl_SysVars '(CMDECHO MENUECHO FILLETRAD OSMODE PDMODE PDSIZE COORDS BLIPMODE ORTHOMODE GRIDMODE PEDITACCEPT DYNMODE)) (defun get_CurrentState () (setq gbl_SysValues (mapcar '(lambda (gbl_SysVars) (cons gbl_SysVars (getvar gbl_SysVars)) ) gbl_SysVars ) ) (princ) ) (defun set_CurrentState () (mapcar '(lambda (gbl_SysValues) (setvar (car gbl_SysValues) (cdr gbl_SysValues)) ) gbl_SysValues ) (princ) ) Quote
Lee Mac Posted July 11, 2019 Posted July 11, 2019 This may not transpire to be the source of the regeneration issue that you are encountering, but you needn't set/reset so many system variables for each use of the program - you need only store/reset the values of those system variables being modified by the program. Here is an example for you to try, based loosely on my Polyline Join program: (defun c:pj ( / ent enx sel val var ) (if (setq sel (ssget "_+.:E:S:L" '( (-4 . "<OR") (0 . "LINE,ARC") (-4 . "<AND") (0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&=") (70 . 1) (-4 . "NOT>") (-4 . "AND>") (-4 . "OR>") ) ) ) (progn (setq var '(cmdecho peditaccept) val (mapcar 'getvar var) ent (entlast) ) (mapcar '(lambda ( a b c ) (if b (setvar a c))) var val '(0 1)) (command "_.pedit" sel "_j" "_all" "" "") (mapcar '(lambda ( a b ) (if b (setvar a b))) var val) (if (and (not (eq ent (setq ent (entlast)))) (setq enx (entget ent))) (princ (strcat "\nPolyline: " (nth (logand 1 (cdr (assoc 70 enx))) '("OPEN" "CLOSED")) "\tVerices: " (itoa (cdr (assoc 90 enx))) ) ) (princ "\nUnable to create polyline from selection.") ) ) ) (princ) ) 1 Quote
sublimation Posted July 12, 2019 Author Posted July 12, 2019 Lee, Thanks a lot! That completely removed the regeneration issue and given me plenty to think about. I've only been using Autolisp for a few weeks so I will have to study some of the techniques you used, but I have a question about one of them. See below: 18 hours ago, Lee Mac said: (progn (setq var '(cmdecho peditaccept) val (mapcar 'getvar var) ----->> ent (entlast) ) ----->> (if (and (not (eq ent (setq ent (entlast)))) (setq enx (entget ent))) Why is ent defined twice? The code seemed to work fine without the first one definition. Am I missing something? Quote
Lee Mac Posted July 12, 2019 Posted July 12, 2019 (edited) 9 hours ago, sublimation said: Thanks a lot! That completely removed the regeneration issue and given me plenty to think about. You're most welcome! 9 hours ago, sublimation said: Why is ent defined twice? Prior to evaluating the PEDIT command I assign the last primary entity in the drawing database to the symbol ent using the entlast function. Then, after calling the PEDIT command, I test whether the value held by the symbol ent points to the same entity as that returned by entlast (and I redefine the ent symbol at the same time). If the entity is the same, this indicates that the PEDIT command has not added any entities to the drawing database and has hence failed to generate a new polyline; as such, the test expression for the if statement is only validated if these entities differ with the new entity assigned to ent being the new polyline generated by the PEDIT command. Edited July 12, 2019 by Lee Mac 2 Quote
sublimation Posted July 15, 2019 Author Posted July 15, 2019 On 7/12/2019 at 5:29 PM, Lee Mac said: Prior to evaluating the PEDIT command I assign the last primary entity in the drawing database to the symbol ent using the entlast function. Then, after calling the PEDIT command, I test whether the value held by the symbol ent points to the same entity as that returned by entlast (and I redefine the ent symbol at the same time). If the entity is the same, this indicates that the PEDIT command has not added any entities to the drawing database and has hence failed to generate a new polyline; as such, the test expression for the if statement is only validated if these entities differ with the new entity assigned to ent being the new polyline generated by the PEDIT command. Fascinating. Thank you again! Quote
Recommended Posts
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.