Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insertion point for a text

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
330 Views, 3 Replies

Insertion point for a text

Hi, I am very new to the Autolisp language.

I'm currently trying to make a code that will generate single-line text with the panel label that I need to input for my task. 

Most components are working, but for some reason, wherever I give as an insertion point, it always generate the text at the origin (0,0,0). Can anybody explain me why it behaves like this?

 

Also, I need some advice on the following two issues that I am trying next:

  - I wanna improve the setup so that whenever I press enter during one of them, the rest will automatically use the previous value (also the reason why I didn't localize some variables) without writing 50 lines for it. Other option would be to use the keyword to change individual value.

  - In order to use this code for my actual work, I have to "overwrite" the previously existing text with the same configuration except its content. How can I click an object and change it using DXF group code (in this case, I only need to change group code 1)?

 

Thank you in advance.

 

(defun C:GetTest(/ temp exit inp txt)
	(if (= (setq temp (getint "\nEnter Current String Number: ")) nil) 
		()(setq strNum temp))
	(if (= (setq temp (getint "\nEnter Current panel Number: ")) nil) 
		()(setq pnlNum temp))
	(if (= (setq temp (getint "\nEnter Number of Strings: ")) nil) 
		()(setq strLim temp))
	(if (= (setq temp (getint "\nEnter Number of Panels: ")) nil) 
		()(setq pnlLim temp))
	(setq exit 0)
	(while (= exit 0)
		(setq inp (getpoint "\nSelect Insertion Point: "))
		(princ inp)
		(setq txt (strcat (itoa pnlNum) "." (itoa strNum)))
		(entmake
			(list
				(cons 0 '"TEXT")
				(cons 8 '"model") 
				(cons 10 inp) 
				(cons 40 3) 
				(cons 1 txt) 
				(cons 50 0) 
				(cons 71 0) 
				(cons 72 1) 
				(cons 73 2) 
			)
		)
		(if (= pnlNum pnlLim) 
			(progn (setq pnlNum 1) (setq strNum (+ strNum 1)))
			(setq pnlNum (+ pnlNum 1))
		)
		(if (> strNum strLim) 
			(progn (alert "You have reached the end of the last string.")
				(setq exit 1))
		)
		
	)
	(princ "End of the Program.")
)

 

Tags (1)
3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... for some reason, wherever I give as an insertion point, it always generate the text at the origin (0,0,0). Can anybody explain me why it behaves like this?

....

 

....
		(setq inp (getpoint "\nSelect Insertion Point: "))
....
		(entmake
			(list
....
				(cons 10 inp) 
....
				(cons 72 1) 
				(cons 73 2) 
....

 


It's because of a peculiarity in the relationship of the 10 code value to the insertion point for Text entities.  For default left-justified Text, 10 goes with the insertion point, and there's also an 11 code that is always (11 0.0 0.0 0.0).  For any other justification, 11 goes with the insertion point, and 10 is the left end of the baseline, which is calculated from the insertion point and the size and content of the Text.  The 10 goes with the left end of the baseline in any case, but only in left-justified Text is that also the insertion point.

 

Your values for the 72 and 73 entries indicate Middle-Center-justified Text, so the insertion point needs to be combined with an 11, rather than a 10.  In my limited experience, (entmake)ing Text this way still requires that a 10 code be included, even if it's going to be recalculated once it makes the Text.  I assume that since you don't supply an 11 entry, it is defaulting to 0,0,0 for that, which would be why that ends up as the insertion point.  I think if you try:

....

  '(10 0.0 0.0 0.0) ; temporary value, will be replaced

  (cons 11 inp) ; rather than 10

....

 

it may work as you expect.

Kent Cooper, AIA
Message 3 of 4
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....

  - In order to use this code for my actual work, I have to "overwrite" the previously existing text with the same configuration except its content. How can I click an object and change it using DXF group code (in this case, I only need to change group code 1)?

.... 


You may be able to use something like this routine, which I think generates new Text in incremented series, with options that may handle your panel number and decimal portions, or maybe this one, which it sounds like has you pick existing Text and changes its content in incremented fashion.  A Search of that Cadalyst website or these Forums for something about incrementing or stepping will probably yield other possibilities.  If you don't find anything that does what you want, it can certainly be worked out.

Kent Cooper, AIA
Message 4 of 4
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....

  - I wanna improve the setup so that whenever I press enter during one of them, the rest will automatically use the previous value (also the reason why I didn't localize some variables) without writing 50 lines for it. Other option would be to use the keyword to change individual value.

.... 


For that part, there are many examples on these Forums that save choices to offer as defaults on subsequent use.  You would want a separate variable name for each, rather than using 'temp' for all of them.

 

Here's an extract from a routine of mine, showing one way to do it for integer values, that should get you started.  All global variables in the routine start with *TAG to avoid interference from those of other routines.  If there's no current value yet, it offers 1 as a default for both the starting integer number and the incrementing value.

 

  (setq

    *TAGint ; [all global variables in this routine start with *TAG to avoid interference from those of other routines
    (cond
      ( (getint
          (strcat
            "\nInitial number <"
            (cond (*TAGint (itoa *TAGint)) ("1"))
              ; offer current value if present; otherwise 1
            ">: "
          ); strcat
        ); getint
      ); User-input condition [nil on Enter]
      (*TAGint); Enter on subsequent use -- prior value
      (1); Enter on first use -- initial default
    ); cond & *TAGint
    *TAGinc
    (cond
      ( (getint
          (strcat
            "\nIncrement numbers by <"
            (cond (*TAGinc (itoa *TAGinc)) ("1")); offer current value if present; otherwise 1
            ">: "
          ); strcat
        ); getint
      ); User-input condition [nil on Enter]
      (*TAGinc); Enter on subsequent use -- prior value
      (1); Enter on first use -- initial default

    ); cond

  ); setq

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost