Author Topic: Copy Increment f1  (Read 2762 times)

0 Members and 1 Guest are viewing this topic.

akdrafter

  • Guest
Copy Increment f1
« on: August 03, 2006, 04:36:21 PM »
I found this routine writen by J.RICHARDSON back in 96. It works on text that has the default justification (LEFT) but when the text is justified to something other than the default....say... middle left... then it places the new incremented text at the same point as the original text. Why?

Thanks in Advance.

Code: [Select]
;TITLE:            COPYINC.LSP
;WRITTEN:      J.RICHARDSON for CAD User Magazine
;DATE:             March 1996
;FUNCTION:     Copy a piece of text which is an integer and increment it by 1
;LIMITATIONS: Since no check is made on the contents of text if a string is
;                        selected then its conversion will be 0 and it will be incremented to


;define error handling function to deal with cancelled commands

(defun c:COPYINC (/ oldent PT1 newent)
   (setq oldent (cdr (entget(car(entsel "Select text: ")))))
   (if (/= (cdr(assoc 0 oldent)) "TEXT")
      (progn
         (princ "No Text Selected")
      )
     
      ;loop until user cancels command
      (while T
         (progn
           
            ;increment text and substitute it in the DXF group 1 entity data
            (setq newent (subst (cons 1 (itoa (1+ (atoi (cdr(assoc 1 oldent)))))) (assoc 1 oldent) oldent))
           
            ;get a new point and substitute the DXF group 10 code with the new point
(setvar "OSMODE" 64);added
(setq PT1 (getpoint "\nSelect Text Insertion Point: "));added
            (setq newent (subst (cons 10 (polar PT1 (DTR 180) 4)) (assoc 10 newent) newent));added (polar PT1 (DTR 180) 4))
           
            ;reset ready to start again           
            (setq oldent (entmake newent))
         )
      )
   )
   
   ;exit cleanly
   (princ)
)

(defun DTR (a);added
(* PI (/ a 180.0));added
);added

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Copy Increment f1
« Reply #1 on: August 03, 2006, 05:55:14 PM »
......at the same point as the original text. Why?
Because only Left, Aligned, & Fit justified texts use ASSOC 10 to define the Text's insertion point. All others use ASSOC 11 and since the code is not modifying the ASSOC 11 it is using that of the original.  One other thing, the Aligned and Fit use BOTH the ASSOC 10 & 11.....
« Last Edit: August 03, 2006, 05:56:16 PM by Jeff_M »

akdrafter

  • Guest
Re: Copy Increment f1
« Reply #2 on: August 03, 2006, 08:32:44 PM »
Jeff,

I have made a bunch of modifications. But, it still does not work correctly. I think you can figure out what I am trying to do by reviewing the code. The problem I am having now is that it works once and then not again. I know it is a simple for you to see the problem, but as usual..not I.

Code: [Select]
;TITLE:            COPYINC.LSP
;WRITTEN:      J.RICHARDSON for CAD User Magazine
;DATE:             March 1996
;FUNCTION:     Copy a piece of text which is an integer and increment it by 1
;LIMITATIONS: Since no check is made on the contents of text if a string is
;                        selected then its conversion will be 0 and it will be incremented to


;define error handling function to deal with cancelled commands
(defun *error* (msg / )
   (princ "\nerror: ")
   (princ msg)
   (terpri)
   (princ)
)
;;;
(defun DTR (a);added
(* PI (/ a 180.0));added
)
;define main program section
(defun c:COPYINC (/ OLDENT HJ VJ NEWENT)

(setq OLDENT (cdr (entget (car (entsel "Select The Text: ")))))
(while (/= (cdr (assoc 0 OLDENT)) "TEXT"); if we did not select any text
(princ "\nNo Text Selected... Select Again..."); alert the user
(setq OLDENT (cdr (entget (car (entsel "Select The Text: "))))); and ask again
);got some text
;;;
(setq HJ (cdr (assoc 72 OLDENT))); Horizontal point for use below
(setq VJ (cdr (assoc 73 OLDENT))); Vertical point for use below
;;;
;loop until user cancels command
(while T
(progn
;increment text and substitute it in the DXF group 1 entity data
;;;
(setq NEWENT (subst (cons 1 (itoa (1+ (atoi (cdr(assoc 1 OLDENT)))))) (assoc 1 OLDENT) OLDENT))
;get a new point and substitute the DXF group 10 or 11 code with the new point that is 4 units to the left or right
(setvar "OSMODE" 64);added
(cond
((and (= VJ 0)(= HJ 0)
(setq NEWENT (subst (cons 10 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 180) 4)) (assoc 10 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Left
((and (= VJ 0)(= HJ 1)
(princ "\nThis Command Does NOT Work on Center Justified Text...end")
(setq T nil)
)
);Center
((and (= VJ 0)(= HJ 2)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 0) 4)) (assoc 10 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Right
((and (= VJ 0)(= HJ 3)
(princ "\nThis Command Does NOT Work on Aligned Justified Text...end")
(setq T nil)
)
);Aligned
((and (= VJ 0)(= HJ 4)
(princ "\nThis Command Does NOT Work on Middle Justified Text...end")
(setq T nil)
)
);Middle
((and (= VJ 0)(= HJ 5)
(princ "\nThis Command Does NOT Work on Fit Justified Text...end")
(setq T nil)
)
);Fit
((and (= VJ 1)(= HJ 0)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 180) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Bottom Left
((and (= VJ 1)(= HJ 1)
(princ "\nThis Command Does NOT Work on Bottom Center Justified Text...end")
(setq T nil)
)
);Bottom Center
((and (= VJ 1)(= HJ 2)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 0) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Bottom Right
((and (= VJ 2)(= HJ 0)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 180) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Middle Left
((and (= VJ 2)(= HJ 1)
(princ "\nThis Command Does NOT Work on Middle Center Justified Text...end")
(setq T nil)
)
);Middle Center
((and (= VJ 2)(= HJ 2)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 0) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Middle Right
((and (= VJ 3)(= HJ 0)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 180) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Top Left
((and (= VJ 3)(= HJ 1)
(princ "\nThis Command Does NOT Work on Top Center Justified Text...end")
(setq T nil)
)
);Top Center
((and (= VJ 3)(= HJ 2)
(setq NEWENT (subst (cons 11 (polar (getpoint "\nSelect Text Insertion Point: ") (DTR 0) 4)) (assoc 11 NEWENT) NEWENT))
(setq OLDENT (entmake NEWENT))
)
);Top Right
)
)
)
(princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Copy Increment f1
« Reply #3 on: August 04, 2006, 12:25:25 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.