Author Topic: dxf code change?  (Read 11581 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
dxf code change?
« Reply #30 on: February 27, 2005, 07:31:14 PM »
I've seen this repeated a couple of times, and feel compelled to comment :
Code: [Select]

  (defun getboundingbox (obj / minpt maxpt)
    (vla-getboundingbox obj 'minpt 'maxpt)
    (mapcar 'vlax-safearray->list (list minpt maxpt))
    (setq llc (vlax-safearray->list minpt)
          urc (vlax-safearray->list maxpt)
    )
    (list llc urc)
  )


This procedure has superfluous expressions ,

If you want a list of the points, this is sufficient.
Code: [Select]
(defun getboundingbox (obj / minpt maxpt)
  (vla-getboundingbox obj 'minpt 'maxpt)
  (mapcar 'vlax-safearray->list (list minpt maxpt))
)



.. and ronjonp ,
perhaps the first item in the locals variable declaration list should be *error*  not *error
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
dxf code change?
« Reply #31 on: February 27, 2005, 11:09:41 PM »
ron
Try this. Create a text stile with a fixed text height say 5 units in height.
Then set it current and run your routine.

You miss copied the following code in your commented version of code and I did not give
you all the lines of code needed. SO here is the code i intended to give you.
Code: [Select]
;;  Check if the drawing height is set to 0:
(setq dwg_style (getvar "textstyle"))          ; get the current textstyle
(setq styledata (tblsearch "style" dwg_style)) ; get the style data
(setq dwg_ht (cdr (assoc 40 styledata)))       ; get the text height for that style
;;  If the height is zero the TEXT command ask for the user to enter the height
;;  If the height in NOT zero the TEXT command does not ask the user for the height
;;  So you my compensate by having two different number of prompts.
(if (= dwg_ht 0)
  (command "text" pt "" "0" txt) ; this one has an extra prompt for the height
  (command "text" pt "0" txt)
) ; endif



In the following code it is tested to see if the LUNITS is 3 or 4
If it is the AREA is divided by 144 to get square feet from square inches.
Then display the matching results.

Code: [Select]
(setq units# (getvar "LUNITS")) ; get the current units code
if (member units# '(3 4))   ;test units# to see if it is 3 or 4
  (setq txt (strcat (rtos (/ obj_area 144) 2 2) " Sq. Ft."))
  (setq txt (strcat (rtos obj_area) " Sq. Units"))
)



Jeff did a good job of explaining the code iterating through a selection set.

Hopefully I made these section more understandable.
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.

ronjonp

  • Needs a day job
  • Posts: 7529
dxf code change?
« Reply #32 on: March 08, 2005, 12:33:14 PM »
So I have another question...:)  How would I set a counter so that the routine adds all the areas in the selset and output a total?

Code: [Select]
;Puts text with objects area in it unless it is 0.00*------Many thanks to the SWAMP.ORG for all the help

(defun c:test (/ *error* u-clayer getboundingbox llc urc s1 index ent obj bbox mpt obj_area txt deltext)
  (command ".undo" "begin")  
(vl-load-com)

;_____________________________
;Error function
;_____________________________

(defun *error* (msg)
   (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    ) ; if
(setvar 'clayer u-clayer)
    (princ)
  ) ;end error function

;_____________________________
;Get User Variables
;_____________________________

(setq u-clayer (getvar 'clayer))
(if (tblsearch "layer" "area")
  (command "-layer" "thaw" "area" "on" "area" "")
  (princ "\n Layer 'area' Created")
)
(command ".-layer" "m" "area" "")
 
  (defun getboundingbox (obj / minpt maxpt)
    (vla-getboundingbox obj 'minpt 'maxpt)
    (mapcar 'vlax-safearray->list (list minpt maxpt))
    (setq llc (vlax-safearray->list minpt)
          urc (vlax-safearray->list maxpt)
    )
    (list llc urc)
  )
  (if (setq sl (ssget '((0 . "LWPOLYLINE,CIRCLE,REGION,POLYLINE,ELLIPSE,REGION,SPLINE"))

               )
      )
    (progn
      (setq index -1)
      (while (< (setq index (1+ index)) (sslength sl))
        (setq ent (ssname sl index))
        (setq obj (vlax-ename->vla-object ent))
        (setq bbox (getboundingbox obj)
              llc (car bbox)
              urc (cadr bbox)
              mpt (list (/ (+ (car llc) (car urc)) 2) (/ (+ (cadr llc) (cadr urc)) 2))
        )

        (setq obj_area (vlax-get-property obj 'area))
        (setq txt (strcat (rtos obj_area)))
        (command "text" "j" "mc" mpt (* (getvar "dimscale") 0.15) "0" txt)

        (princ)
      )
    )
  )
(setq deltext (setq s1 (ssget "x"'((0 . "Text")(8 . "area")(1 . "0.00*")))))
(command ".erase" deltext "")
(command ".undo" "end")
(princ)
(*error* "")
(setvar 'clayer u-clayer)
(princ (strcat (itoa index) " entities processed..."))
(princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
dxf code change?
« Reply #33 on: March 08, 2005, 01:06:43 PM »
I think this will help.

Code: [Select]

      (setq n (1- (sslength sl)))
      (while (>= n 0)
        (command "_.area" "_o" (ssname sl n))
        (setq a (+ a (getvar "area"))
              n (1- n)))
      (prompt
(strcat "The TOTAL AREA of the selected\nItems is "
(strcat (rtos (/ a 144) 2 3)  " Square Feet.")))
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

ronjonp

  • Needs a day job
  • Posts: 7529
dxf code change?
« Reply #34 on: March 08, 2005, 05:38:15 PM »
Thanks dvarino  :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC