Author Topic: how to change the extrusion of a 3d solid  (Read 1855 times)

0 Members and 1 Guest are viewing this topic.

danadrian.baluta@yahoo.co

  • Guest
how to change the extrusion of a 3d solid
« on: April 28, 2015, 12:18:29 PM »
I made a function that subtracts automatically windows from a wall. I copy a polyline drawn onto the wall and extrude it by a meter, then subtract it. It works fine, but, when I get an error that the polyline isn't planar (although it is), it's automatically extruded to a random number greater than 40.000. I'm trying to detect this a d to reduce the extrusion back to 1, but it doesn't seem to work. I can't entmod an entity that has (0 . ACSH_EXTRUSION_CLASS). I see that it's a class, not an entiy, but it's this entity that gives me the extrusion vector.
Here's the code:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:punch( / *error*)
  2.   (defun *error* ( msg )
  3.     (setvar "osmode" osm)
  4.     (command-s "_.undo" "e")
  5.     (setvar "cmdecho" cmd)
  6.     (princ msg)
  7.   )
  8.   (setq osm (getvar "osmode")
  9.         cmd (getvar "cmdecho"))
  10.   (setvar "cmdecho" 0)
  11.   (command-s "_.undo" "be")
  12.   (setvar "osmode" 0)
  13.   (princ "\nWindows to punch:")
  14.   (setq windlist (ssget (list '(0 . "LWPOLYLINE"))))
  15.   (if (null windlist)(exit))
  16.   (setq wall (car (entsel "\nWall to be punched:")))
  17.   (if (null wall)(exit))
  18.   (setq nct (sslength windlist)
  19.         ct 0)
  20.   (while (< ct nct)
  21.     (setq wind (ssname windlist ct))
  22.     (command-s "_.ucs" "e" wind)
  23.     (command-s "_.copy" wind "" "0,0,0" "0,0,0.05" "")
  24.     (setq hole (entlast))
  25.     (command-s "_.extrude" hole "" "-1.05")
  26.     (setq hole (entlast))
  27.     (command "copy" hole "" "0,0,0" "0,0,0" "")
  28.     (setq holent (entget hole))
  29.     (princ "\n=====================================holent:\n")(princ holent)
  30.     (setq step1a (cdr (assoc 350 holent)))
  31.     (setq step1 (entget step1a))
  32.     (princ "\n=====================================step1:\n")(princ step1)
  33.     (setq step2a (cdr (assoc 360 step1)))
  34.     (setq step2 (entget step2a))
  35.     (princ "\n=====================================step2:\n")(princ step2)
  36.     (setq step3a (cdr (assoc 360 step2)))
  37.     (setq step3 (entget step3a))
  38.     (princ "\n=====================================step3:\n")(princ step3)
  39.     (setq step4 (cdr (assoc 10 step3)))
  40.     (princ "\n=====================================step4:\n")(princ step4)
  41.     (setq mult (abs (car step4)))
  42.     (if (< mult (abs (cadr step4))) (setq mult (abs (cadr step4))))
  43.     (if (< mult (abs (caddr step4))) (setq mult (abs (caddr step4))))
  44.     (princ mult)
  45.     (if (> mult 2)
  46.       (progn
  47.         (setq step4 (list (/ (car step4) mult)(/ (cadr step4) mult)(/ (caddr step4) mult)))
  48.         (setq step3 (subst (cons 10 mult) (assoc 10 step3) step3))
  49.                 (princ "aci")
  50.         (entmod step3a)
  51.         (entupd)
  52.       )
  53.     )
  54.     (princ step4)
  55.     (command-s "_.subtract" wall "" hole "")
  56.     (setq ct (1+ ct))
  57.   )
  58.   (setvar "osmode" osm)
  59.   (command-s "_.undo" "e")
  60.   (setvar "cmdecho" cmd)
  61.   (princ)
  62. )

The funciton that gets hte extrusion vector looks originally like this:
Code - Auto/Visual Lisp: [Select]
  1. (setq solent (entsel "\nSelect solid : "))
  2. (setq slist (entget (car solent)))
  3. (setq extvector (cdr (assoc 10
  4. (entget (cdr (assoc 350 slist))))))))))))
  5. (setq extHeight (sqrt (apply '+(mapcar '* extvector extvector))))
  6.  

What I could do is changing back the extrusion or preventing this faulty extrusion from happening.
The polylines that I extrude are fine, most of the times just rectangles, but I still get the error now and then.

Thank you!

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: how to change the extrusion of a 3d solid
« Reply #1 on: April 28, 2015, 12:35:36 PM »
Just stab in the dark...

Have you tried to change :
Code - Auto/Visual Lisp: [Select]
  1. (entmod step3a)
  2.  

To this :
Code - Auto/Visual Lisp: [Select]
  1. (entmod step3)
  2.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

danadrian.baluta@yahoo.co

  • Guest
Re: how to change the extrusion of a 3d solid
« Reply #2 on: April 29, 2015, 05:31:03 AM »
Thank you ribarm, that was my mistake, but still i got 'invalid dxf group' error, so I found a workaround.
I just slice the 3d object if the extrusion is not what i ordered :D.
It's not spectacular, but it gets the job done.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:punch( / *error*)
  2.   (defun *error* ( msg )
  3.     (setvar "osmode" osm)
  4.     (command-s "_.undo" "e")
  5.     (setvar "cmdecho" cmd)
  6.     (princ msg)
  7.   )
  8.   (setq osm (getvar "osmode")
  9.         cmd (getvar "cmdecho"))
  10.   (setvar "cmdecho" 0)
  11.   (command-s "_.undo" "be")
  12.   (setvar "osmode" 0)
  13.   (princ "\nWindows to punch:")
  14.   (setq windlist (ssget (list '(0 . "LWPOLYLINE"))))
  15.   (if (null windlist)(exit))
  16.   (setq wall (car (entsel "\nWall to be punched:")))
  17.   (if (null wall)(exit))
  18.   (setq nct (sslength windlist)
  19.         ct 0)
  20.   (while (< ct nct)
  21.     (setq wind (ssname windlist ct))
  22.     (command-s "_.ucs" "e" wind)
  23.     (command-s "_.copy" wind "" "0,0,0" "0,0,0.05" "")
  24.     (setq hole (entlast))
  25.     (command-s "_.extrude" hole "" "-1.05")
  26.     (setq hole (entlast))
  27.     (setq step4 (cdr (assoc 10 (entget (cdr (assoc 360 (entget (cdr (assoc 360 (entget (cdr (assoc 350 (entget hole)))))))))))))
  28.     (setq mult (abs (car step4)))
  29.     (setq mult (abs (car step4)))
  30.     (if (< mult (abs (cadr step4))) (setq mult (abs (cadr step4))))
  31.     (if (< mult (abs (caddr step4))) (setq mult (abs (caddr step4))))
  32.     (if (> mult 2)
  33.         (command-s "slice" hole "" "3p" "0,0,-1" "1,0,-1" "1,1,-1" "0,0,1")
  34.     )
  35.     (command-s "_.subtract" wall "" hole "")
  36.     (setq ct (1+ ct))
  37.   )
  38.   (setvar "osmode" osm)
  39.   (command-s "_.undo" "e")
  40.   (setvar "cmdecho" cmd)
  41.   (princ)
  42. ); c:punch