TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dussla on June 23, 2022, 11:03:20 AM

Title: How to solve the problem that region object cannot be extrude
Post by: dussla on June 23, 2022, 11:03:20 AM
hi frends
i need some help
I made some extrude code modifications

But this code doesn't extrude the region

Can you help me make this possible ?

Code: [Select]
(defun c:c4 ( /  ss)


   (vl-load-com)
    (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
 
 
   

   
(if (setq ss (ssget ))
 
 
 
 



(progn


         (if ( not de-hi ) (setq de-hi  200 ) )
(setq detemp-hi (getreal (strcat "\n  height   <"  (rtos de-hi)  ">:")))
(if detemp-hi (setq de-hi detemp-hi))



(vlax-for obj (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))

           
     


(setq reg (vl-catch-all-apply
'vlax-invoke
(list sp 'addRegion(list obj)))
)



(or (vl-catch-all-error-p reg)
(and
  (vla-addExtrudedSolid  sp  (car reg) de-hi 0.0   )
  (vla-delete (car reg))
)
)
)




 
)
 
 
)
 
 
  )
Title: Re: How to solve the problem that region object cannot be extrude
Post by: ronjonp on June 23, 2022, 12:33:59 PM
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:c4 (/ de-hi detemp-hi reg sp ss)
  2.   (if (setq ss (ssget))
  3.     (progn
  4.       (if (not de-hi)
  5.         (setq de-hi 200)
  6.       )
  7.       (setq detemp-hi (getreal (strcat "\n  height   <" (rtos de-hi) ">:")))
  8.       (if detemp-hi
  9.         (setq de-hi detemp-hi)
  10.       )
  11.       (vlax-for obj (setq
  12.                     )
  13.         ;; If we already have a region extrude it
  14.         (if (= "AcDbRegion" (vla-get-objectname obj))
  15.           (vla-addextrudedsolid sp obj de-hi 0.0)
  16.           ;; Else try to create a region and extrude it
  17.           (or (vl-catch-all-error-p
  18.                 (setq reg (vl-catch-all-apply 'vlax-invoke (list sp 'addregion (list obj))))
  19.               )
  20.               (and (vla-addextrudedsolid sp (car reg) de-hi 0.0) (vla-delete (car reg)))
  21.           )
  22.         )
  23.       )
  24.     )
  25.   )
  26.   (princ)
  27. )
Title: Re: How to solve the problem that region object cannot be extrude
Post by: dussla on June 23, 2022, 01:58:44 PM
really really  really really   thank you .
I'm sorry, but can I ask you one more thing?
I added the following code.
However, the harm does not become an extrud.
pls Can you help?

"command  extrude" is possible
Code: [Select]

(defun h2r  ( ss num / el   i h reg sp )
(vl-load-com)
 
(or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
 

  (setq el (entlast))
  (setq s (ssadd))
 
  (repeat (setq i (sslength ss))
    (setq h (ssname ss (setq i (1- i))))
(setq la (cdr (assoc 8 (entget h))))
  (setvar "clayer" la)
    (command "_.-HATCHEDIT" h "_B" "_R" "_N")
    (command "_.-HATCHEDIT" h "_DI")
    (if (not (eq el (entlast))) (ssadd (entlast) s))
  )
   
     (command "_erase" ss "")
 
  (vlax-for obj (setq
  s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
)


;; If we already have a region extrude it
(if (= "AcDbRegion" (vla-get-objectname obj))
  (vla-addextrudedsolid sp obj num 0.0)
  ;; Else try to create a region and extrude it
  (or (vl-catch-all-error-p
(setq reg (vl-catch-all-apply 'vlax-invoke (list sp 'addregion (list obj))))
  )
  (and (vla-addextrudedsolid sp (car reg) num 0.0) (vla-delete (car reg)))
  )
)
  )
   
 
(princ)
   )


( defun c:hs2 ( / )

(setq ss (ssget "_:L" '((0 . "HATCH"))))
( h2r  ss 100 )


)
Title: Re: How to solve the problem that region object cannot be extrude
Post by: ScottMC on June 25, 2022, 08:12:45 PM
 [a2k] won't run w/o adding:

Code: [Select]
(defun c:c4 (/ de-hi detemp-hi reg sp ss)
  (vl-load-com)

      (setq acadObj (vlax-get-acad-object))             ;; <-- inserted lines..
    (setq doc (vla-get-ActiveDocument acadObj))   ;; <--  got from:
    (setq sp (vla-get-ModelSpace doc))                 ;; <--

;;; https://help.autodesk.com/view/OARX/2020/DEU/?guid=GUID-B9DEA4C5-EDAA-4CC6-93B0-394D5991A0E6
  (or *acdoc* (setq *acdoc* (vla-get-activedocument (vlax-get-acad-object))))
....
....
(princ)
)

Title: Re: How to solve the problem that region object cannot be extrude
Post by: BIGAL on June 25, 2022, 08:51:49 PM
Clock on # this is for code section.
Title: Re: How to solve the problem that region object cannot be extrude
Post by: dussla on June 25, 2022, 11:34:34 PM
Wow  wow really thank you~
Title: Re: How to solve the problem that region object cannot be extrude
Post by: ribarm on June 26, 2022, 01:00:59 AM
@dussla,
please review Ron's code and if you will ask yourself for entity type you are selecting is it regionable or not...
After (vlax-for obj ...
consider putting
  (if (and (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-curve-getendpoint) (list obj)))) (vlax-curve-isclosed obj))
    ...
...
Title: Re: How to solve the problem that region object cannot be extrude
Post by: dussla on June 26, 2022, 02:45:31 AM
thank you  thank you for good advice
Title: Re: How to solve the problem that region object cannot be extrude
Post by: ribarm on June 27, 2022, 11:02:03 PM

thank you  thank you for good advice