Jump to content

lisp to select all hatch then calculate total area


SWfangirl

Recommended Posts

Hello,:oops:

My coworker found this lisp and it doesn't appear to be working correctly. I honestly still don't know enough about lisp to figure it out. As the title says it should select all of the hatch in a drawing then calculate the total area. If anyone can help I would really appreciate it. Again this is not something either of us wrote it was found in the autodesk discussion groups. When I load it this is the error I get. ; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

[font=Times New Roman][size=3](defun c:HatchAreas (/ sset i area obj)[/size][/font]
[size=3][font=Times New Roman](if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)[/font][/size]
[size=3][font=Times New Roman](progn[/font][/size]
[size=3][font=Times New Roman](prompt "\nSelect hatches: ")[/font][/size]
[size=3][font=Times New Roman](if (setq sset (ssget '((0 . "hatch"))))[/font][/size]
[size=3][font=Times New Roman](progn[/font][/size]
[size=3][font=Times New Roman](setq[/font][/size]
[size=3][font=Times New Roman]i (1- (sslength sset))[/font][/size]
[size=3][font=Times New Roman]area 0)[/font][/size]
[size=3][font=Times New Roman](while (>= i 0)[/font][/size]
[size=3][font=Times New Roman](setq[/font][/size]
[size=3][font=Times New Roman]obj (vlax-ename->vla-object (ssname sset i))[/font][/size]
[size=3][font=Times New Roman]area (+ area (vla-get-area obj)))[/font][/size]
[size=3][font=Times New Roman](setq i (1- i)))[/font][/size]
[size=3][font=Times New Roman](alert[/font][/size]
[size=3][font=Times New Roman](strcat[/font][/size]
[size=3][font=Times New Roman]"\nTotal area = "[/font][/size]
[size=3][font=Times New Roman](if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))[/font][/size]
[size=3][font=Times New Roman](strcat[/font][/size]
[size=3][font=Times New Roman](rtos area 2)[/font][/size]
[size=3][font=Times New Roman]" sq. in. ("[/font][/size]
[size=3][font=Times New Roman](rtos (/ area 144) 2)[/font][/size]
[size=3][font=Times New Roman]" sq. ft.)")[/font][/size]
[size=3][font=Times New Roman](rtos area))))))))[/font][/size]
[size=3][font=Times New Roman](princ))[/font][/size]

Edited by SLW210
Link to comment
Share on other sites

Check this one buddy .:)

 

(defun c:Test (/ ar ss sset i vl e)
 ;; Tharwat 27. 06. 2011
 (setq ar 0)
 (vl-load-com)
 (if
   (setq ss (ssget "_x" '((0 . "HATCH"))))
    (repeat
      (setq i (sslength ss))
       (setq sset (ssname ss (setq i (1- i))))
       (setq vl (vlax-ename->vla-object sset))
       (setq e (entget sset))
       (setq ar (+ ar (vla-get-area vl)))
    )
    (princ)
 )
 (alert
   (strcat "\n"
           (strcat "Area of Hatches :" " " (rtos ar 2))
   )

 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

Hello,:oops:

My coworker found this lisp and it doesn't appear to be working correctly. I honestly still don't know enough about lisp to figure it out. As the title says it should select all of the hatch in a drawing then calculate the total area. If anyone can help I would really appreciate it. Again this is not something either of us wrote it was found in the autodesk discussion groups. When I load it this is the error I get. ; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

[font=Times New Roman][size=3](defun c:HatchAreas (/ sset i area obj)[/size][/font]
[size=3][font=Times New Roman](if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)[/font][/size]
[size=3][font=Times New Roman](progn[/font][/size]
[size=3][font=Times New Roman](prompt "\nSelect hatches: ")[/font][/size]
[size=3][font=Times New Roman](if (setq sset (ssget '((0 . "hatch"))))[/font][/size]
[size=3][font=Times New Roman](progn[/font][/size]
[size=3][font=Times New Roman](setq[/font][/size]
[size=3][font=Times New Roman]i (1- (sslength sset))[/font][/size]
[size=3][font=Times New Roman]area 0)[/font][/size]
[size=3][font=Times New Roman](while (>= i 0)[/font][/size]
[size=3][font=Times New Roman](setq[/font][/size]
[size=3][font=Times New Roman]obj (vlax-ename->vla-object (ssname sset i))[/font][/size]
[size=3][font=Times New Roman]area (+ area (vla-get-area obj)))[/font][/size]
[size=3][font=Times New Roman](setq i (1- i)))[/font][/size]
[size=3][font=Times New Roman](alert[/font][/size]
[size=3][font=Times New Roman](strcat[/font][/size]
[size=3][font=Times New Roman]"\nTotal area = "[/font][/size]
[size=3][font=Times New Roman](if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))[/font][/size]
[size=3][font=Times New Roman](strcat[/font][/size]
[size=3][font=Times New Roman](rtos area 2)[/font][/size]
[size=3][font=Times New Roman]" sq. in. ("[/font][/size]
[size=3][font=Times New Roman](rtos (/ area 144) 2)[/font][/size]
[size=3][font=Times New Roman]" sq. ft.)")[/font][/size]
[size=3][font=Times New Roman](rtos area))))))))[/font][/size]
[size=3][font=Times New Roman](princ))[/font][/size][/quote]
Try adding (vl-load-com) to the code. You need to load the Visual LISP/ActiveX function library.

Edited by SLW210
Link to comment
Share on other sites

; error: no function definition: VLAX-ENAME->VLA-OBJECT

 

Check this one buddy .:)

 

(defun c:Test (/ ar ss sset i vl e)
 (setq ar 0)
 (vl-load-com)
 (if
   (setq ss (ssget "_x" '((0 . "HATCH"))))
    (repeat
      (setq i (sslength ss))
       (setq sset (ssname ss (setq i (1- i))))
       (setq vl (vlax-ename->vla-object sset))
       (setq e (entget sset))
       (setq ar (+ ar (vla-get-area vl)))
    )
    (princ)
 )
 (alert
   (strcat "\n"
           (strcat "Area of Hatches :" " " (rtos ar 2))
   )

 )
 (princ)
)

 

Try adding (vl-load-com) to the code. You need to load the Visual LISP/ActiveX function library.

 

:lol: ........

Link to comment
Share on other sites

Wonder why ! :?

 

That's even funnier. :P

 

The OP needed a toothpick, and you gave them a tree.

 

In other words, you chose to work harder... LoL

Link to comment
Share on other sites

The OP needed a toothpick, and you gave them a tree.

The OP had a box of toothpicks, but couldn't open them. He cut down the tree and whittled out a toothpick, rather than showing them how, or just opening the box for them.

Link to comment
Share on other sites

The OP had a box of toothpicks, but couldn't open them. He cut down the tree and whittled out a toothpick, rather than showing them how, or just opening the box for them.

 

That's fair.

 

... And don't get me wrong, I know I've done the same in the past. That's why it's funny to me.

Link to comment
Share on other sites

That's fair.

 

... And don't get me wrong, I know I've done the same in the past. That's why it's funny to me.

It's all funny to me.

Link to comment
Share on other sites

That's even funnier. :P

 

The OP needed a toothpick, and you gave them a tree.

 

In other words, you chose to work harder... LoL

 

I hope that they would get the fruit of it , not the mood. :whistle:

Link to comment
Share on other sites

I hope that they would get the fruit of it , not the mood. :whistle:

 

Wow... a self-inflicted face-palm... haven't seen one of those in a while. lmao

Link to comment
Share on other sites

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