Lisp coordinates sumation problem

Lisp coordinates sumation problem

Anonymous
Not applicable
1,209 Views
6 Replies
Message 1 of 7

Lisp coordinates sumation problem

Anonymous
Not applicable

Hello,

 

I'm new to LISP and trying to get a lisp that goes through all Layouts and "prints" a value of each viewport scale.
I managed to do all of above, but got stuck on a simple sumation problem.

 

In a case when there is more viewports on layout, or when they are on negative side of paperspace,  desired text is not offseting, its like lisp coudn't add offset value "a" to a coordinates. This does not happen when there is only one viewport in positive part of layout.

 

Do you have any idea what am I doing wrong?

 

Thanks in advance!

Tomasz

 

(vl-load-com)
(princ "WN- for scale")

(defun C:WN (/		   intCount	 intCountLength
	     Scale	   CenterVar	 Center	       CenterX
	     CenterY	   LAY		 ssALL	       intCountLengthDel
	   
	    )

  (setq LAY (getvar "ctab"))
  ;;(setvar "cmdecho" 0)
  (setq a (float 10))  ;;offset "a" set to 10

  (foreach layout (layoutlist)

    (setvar "ctab" layout)
    ;;goes through all layuts
    (progn
      (setq ssAll(ssget "_X"(list (cons 410 (getvar "ctab")) (cons 0 "Viewport"))))
      ;;select ALL vieports  on selectes layout           
      (setq intCountLengthDel (sslength ssAll))
      ;;amount of entities in ss
      (ssdel (ssname ssAll (1- intCountLengthDel)) ssAll)
      ;;delete last entity from selection set(layout vieport)
      (setq intCountLength (sslength ssAll))
      (setq intCount intCountLength)
    
    (while (> intCount 0)
      ;;goes through viewports
      (progn
	(setq intCount (1- intCount))
	(setq entAll (ssname ssAll intCount))
	(setq OBJEname (vlax-ename->vla-object entAll))
	(setq Scale (vla-Get-CustomScale OBJEname))
	;;read scale value in decimal 
	(setq CenterVar (vla-Get-Center OBJEname))
	(setq Center (vlax-safearray->list (vlax-variant-value CenterVar)))
	(setq Width (vla-Get-Width OBJEname))
	(setq CenterX(+ a (- (car Center) (/ (vla-Get-Width OBJEname) 2))))
	;;X coordinates +a (offset)
	(setq CenterY (+ a (- (cadr Center) (/ (vla-Get-Height OBJEname) 2))))
	;;Y coordinates +a (offset)
	(command "._text"(list CenterX CenterY)2.5 0(strcat "SCALE 1:" (rtos (/ 1 Scale)))"")
	;;
      )
      (princ)
      ;;progn
     )
     )
    (princ)
    ;;while

  )
  ;;foreach    ;;) 

  (setvar "ctab" LAY)
  ;;(setvar "cmdecho" 1)
  (princ)
)
0 Likes
Accepted solutions (1)
1,210 Views
6 Replies
Replies (6)
Message 2 of 7

dbhunia
Advisor
Advisor
Accepted solution

Change this line......

 

(command "._text"(list CenterX CenterY)2.5 0(strcat "SCALE 1:" (rtos (/ 1 Scale)))"")

 

to this ..... 

 

(command "._text" "_none" (list CenterX CenterY) 2.5 0 (strcat "SCALE 1:" (rtos (/ 1 Scale))))

And then try .... I did not get anything else wrong......

 

otherwise post a sample drawing....

 

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 7

dlanorh
Advisor
Advisor
Cannot see anything obvious. Could you post a drawing (autocad 2010 format)? It only needs to contain the problem viewport (s), nothing else.

I am not one of the robots you're looking for

0 Likes
Message 4 of 7

Anonymous
Not applicable

Thank You, it works!

 

But could You please explain what - "_none" - stands for? 

0 Likes
Message 5 of 7

dbhunia
Advisor
Advisor

Temporarily disabling the "snap" mode when inserting the text at calculated point otherwise it can snap to other point depending on your zoom label .....

 

Read This .......

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

 

...
      (setq ssAll(ssget "_X"(list (cons 410 (getvar "ctab")) (cons 0 "Viewport"))))
      ;;select ALL vieports  on selectes layout           
      (setq intCountLengthDel (sslength ssAll))
      ;;amount of entities in ss
      (ssdel (ssname ssAll (1- intCountLengthDel)) ssAll)
      ;;delete last entity from selection set(layout vieport)
      (setq intCountLength (sslength ssAll))
      (setq intCount intCountLength)
    
    (while (> intCount 0)
      ;;goes through viewports
      (progn
	(setq intCount (1- intCount))
	(setq entAll (ssname ssAll intCount))
	(setq OBJEname (vlax-ename->vla-object entAll))
...

 

This whole part you can replace with just these...

(if (setq ss (ssget "_X" (list (cons 410 layout) '(0 . "VIEWPORT") '(-4 . "!=") '(69 . 1))))
      (repeat (setq i (sslength ss))
        (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
        ...))

 

And really don't need the 'a' as a real, but if so, (setq 10.) would be enough.

 

I would also consider a more reliable way of text creating. Here is no "none" needed.

(entmake (list (cons 0 "TEXT")
               (cons 10 (list CenterX CenterY))
               (cons 40 (getvar 'TEXTSIZE))
               (cons 1  (strcat "SCALE 1:" (rtos (/ 1. Scale))))
               (cons 7  (getvar 'TEXTSTYLE))))

Look HERE for some more info.

 

Those are just some tips to consider.

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thanks, I' will study Your version of code and try to simplify mine!

 

Regards!

0 Likes