Jump to content

Recommended Posts

Posted

I have a lisp that will invoke the AutoCAD MASSPROP command then paste the results directly into AutoCAD close to the centroid of the picked REGION.
This lisp was written for me by the very helpful Cadtutor poster pBe.
For it to work I have to ensure that there is a folder created and named : - C:/temp
The lisp reads and manipulates the standard created Massprop.mpr file, then pastes it into the drawing.

I have been using this in AutoCAD 2010 and now in AutoCAD 2016.
I am suddenly noticing strange behaviour?
The mass prop figures are correct but the text insertion is not in the correct place. It's correct in the x and y direction but not in the z direction.
It's elevated above the UCS in the z direction.

Not sure how long it's been doing this. It's not easily noticeable unless you switch to an isometric view.
Maybe I have tripped some variable or maybe it's an AutoCAD 2016 thing. Really mystified so I am kindly asking for help here.

 

I would be grateful for anybody's help.

 

Here is the lisp: -

(Note that I only have a very basic knowledge of lisp)

 

;
; CALCULATION OF MASS PROPERTIES (Note: Make a folder C:/temp)
; Cadtutor. Thanks to pBe
; https://www.cadtutor.net/forum/topic/34415-append-text-to-file/?do=findComment&comment=279638
;
(defun c:MPmm (/ ss ptx fn fn1 str)
(vl-load-com)
  (defun Text (pt hgt str sty)
    (entmakex (list (cons 0 "TEXT")
      (cons 10 pt)
      (cons 40 hgt)
      (cons 7 sty) 
      (cons 1 str)
       )
    )
  )
  (setq txtlst nil)
  (if (setq ss (ssget "_+.:E:S" '((0 . "REGION"))))
    (progn
      (command "_.UCS"
        "_Origin"
         (setq ptx (vlax-safearray->List
      (variant-value
        (vlax-get-property
          (vlax-ename->vla-object
     (cadar (ssnamex ss))
          )
          'centroid
        )
      )
    )
  )
      )
      (command "point" "0,0,0")
      (command "massprop"
        ss
        ""
        "y"
        (setq fn
        "c:/temp/mass.mpr"
        )
      )
      (terpri)
      (command "ucs" "w")
      (progn
 (setq fn1 (open fn "r"))
 (read-line fn1)
 (while
   (setq str (read-line fn1))
    (setq txtlst (cons str txtlst))
 )
 (close fn1)
      )
      (setq Txtpt (list (car ptx)
   (- (cadr ptx) (* (getvar 'Textsize) 1.70) )
   (last ptx)
    )
      )
      (mapcar (function (lambda (lst1 lst2)
     (Text (trans (setq Txtpt
           (list
      (car Txtpt)
      (- (cadr Txtpt)
         (* (getvar 'Textsize)
            1.70
         )
      )
      (last Txtpt)
           )
    ) 1 0)
    (getvar 'Textsize)
    (strcat lst1 lst2)(getvar 'Textstyle)
     )
   )
       )
       (reverse txtlst)
       '(""  ""   " mm2"  " mm"    " mm"    " mm"
  " mm"  " mm"   " mm4"  " mm4"  " mm2"  " mm"
  " mm"  ""   " mm4"  " mm4"
        )
      )
    )
  )
  (princ)
)

 

Posted

region centroid is (x y) not (x y z)

delete at line 56 & 68 respectively 


(last ptx) 

(last Txtpt)

 

Posted

That's it!!!
Thank you so much for fixing this for me.

 

I guess the lisp, as I had it, has been like that all along except I never really noticed the Z elevation anomaly until a few days ago.

 

So pleased you responded hanhphuc.
Big smile on my face now. I am very grateful to you.

 

Posted
8 minutes ago, Manila Wolf said:

That's it!!!
Thank you so much for fixing this for me.

 

I guess the lisp, as I had it, has been like that all along except I never really noticed the Z elevation anomaly until a few days ago.

 

So pleased you responded hanhphuc.
Big smile on my face now. I am very grateful to you.

 

 

fwd to author @pBe :)

 

 

Posted
3 minutes ago, hanhphuc said:

fwd to author @pBe :)

 

That's a good suggestion hanhphuc, I will do that.

Cheers.

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