Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

extrude code problem

34 REPLIES 34
SOLVED
Reply
Message 1 of 35
anycganycgJ8A6A
1198 Views, 34 Replies

extrude code problem

hi freinds 

always thank you for helping.

i made this code as refering  good freind code.

this code is to  extrude  with txt in polyline .

 

but that is some error.

  (error: bad argument value: AcDbCurve 42)

i atthed file 

sorry can you help again .

(defun c:edt ( /  ss)

	
   (vl-load-com)
    (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  
    (setq oldec (getvar "cmdecho"))
	(setvar "cmdecho" 0)
	(setvar "osmode" 0)
	(setvar "cecolor" "bylayer")
  
  (UndoBegin *acdoc*)
  
  (setq cl2 (getvar "clayer"))
  
   (setq sp (vla-get-ModelSpace *acdoc*))
      
	(if (setq ss (ssget ))
  		
			(progn
							(vlax-for obj (setq
							  ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
							)
						
								(if  (vlax-curve-isclosed obj)
								   
										   (progn
														(setq la (vla-get-layer obj))
													(setvar "clayer" la)
														 (setq pts (mapcar 'cdr (vl-remove-if '(lambda (obj) (/= (car obj) 10)) obj)))
									
														( if (setq s (  ssget "_WP" pts '((0 . "text"))  )   )
														
														
																(progn
																
																		(setq en (ssname s 0))
																		(setq elist (entget en))
																		(setq txt (cdr (assoc 1 elist)))
																		(setq sum  (atof txt) )
																		(if (= "AcDbRegion" (vla-get-objectname obj))
																	  (vla-addextrudedsolid sp obj (+ (* sum 3300) 2000) 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) (+ (* sum 3300) 2000) 0.0) (vla-delete (car reg)))
																			  )
																			)	
																			(vla-Erase obj)
													)		
																	
														)		
												
												)		
									
								)	
				)						
									
			)
		)
	 (setvar "clayer" cl2)
	(UndoEnd *acdoc*)	
	(setvar "osmode" 35 ) 
    )

 

34 REPLIES 34
Message 2 of 35


@anycganycgJ8A6A wrote:

hi freinds 

....

but that is some error.

....


That is never enough information.  Tell us what the error is, so we know where to start looking.

 

And if you put code into a code window [pick on the  </>  icon], indentations will be preserved, which make it much easier to read what's going on.  I would also suggest removing the empty lines.

Kent Cooper, AIA
Message 3 of 35

really sorry
thank you for good advice ~
Message 4 of 35
ronjonp
in reply to: anycganycgJ8A6A

@anycganycgJ8A6A 

Update your first SSGET to use a polyline filter:

 

 

(setq ss (ssget '((0 . "LWPOLYLINE"))))

 

 

You also might look at THIS post. It does something very similar. All you need to update is the math on the extrusion and setting the current layer.

 

Message 5 of 35

The first time you (setq ss ...) for a selection set, there is no restriction on object type(s) allowed.  If that selection includes things that are not (vlax-curve-...)-class objects [a Block gives 42, Text gives 43, I haven't checked other things], you will get that message when it tries to check whether such an object is closed.  Try adding a filter list to that first (ssget) function, to limit the selection to objects that (vlax-curve-...) functions can work with.

Kent Cooper, AIA
Message 6 of 35
anycganycgJ8A6A
in reply to: ronjonp

Really thank you for answering
Yhanj you for good link
Message 7 of 35

Thank you for good advice .
Always thank you .
Message 8 of 35
anycganycgJ8A6A
in reply to: ronjonp

hi teacher~

i have a problem again .

i tested your link .

but i can not extrude.

this attached file is gis file.

i dont know why this can not extrude.

pls can you test ?

 

Message 9 of 35
-didier-
in reply to: anycganycgJ8A6A

Bonjour @anycganycgJ8A6A 

 

With AutoCAD 2021, there is no problem with the "Extrude" command.

All is OK.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

Didier Aveline

EESignature

Message 10 of 35


@anycganycgJ8A6A  a écrit :

hi teacher~

i have a problem again .

i tested your link .

but i can not extrude.

this attached file is gis file.

i dont know why this can not extrude.

pls can you test ?

 


@anycganycgJ8A6A 

Hi,

The reason for this not working is that your polylines are closed manually (and also have the property of being closed).
This causes a duplicate vertex at the end which interferes with the lisp for polygonal window selection of the text to determine the extrusion height.
Solutions:
1 Edit your polyline to remove the last vertex.
2 Remove last vertex from list provided to (ssget "_WP") in code: bad solution

3 Test if the penultimate element is equal to the last element (with a fuzz) and in this case delete it before submitting the list to (ssget "_WP")

Message 11 of 35


@CADaSchtroumpf wrote:

@anycganycgJ8A6A  a écrit :

... i can not extrude. ....


@anycganycgJ8A6A 

Hi,

The reason for this not working is that your polylines are closed manually (and also have the property of being closed).
This causes a duplicate vertex at the end ....


For AutoCAD 2020 that I have here, that is not a problem -- it Extrudes those successfully.  But if that isn't allowed in some versions, here's a routine to fix that kind of Polyline:

;|  PLFixClose.lsp [command name: PLFC = PolyLine Fix-Close]
To Fix selected lightweight Polylines that were drawn with last
  vertices at the same locations as their start points, and then
  Closed, resulting in coincident vertices at the start/end.
  Removes the original last vertex.
User selection can include non-qualifying Polylines, whether
  open or "properly" closed, which will be left alone.
Kent Cooper, 11 August 2022
|;
(vl-load-com)
(defun C:PLFC (/ ss n ent edata obj coords)
  (if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE") (-4 . "&") (70 . 1))))
    (repeat (setq n (sslength ss)); then
      (setq
        ent (ssname ss (setq n (1- n)))
        edata (entget ent)
        obj (vlax-ename->vla-object ent)
        coords (vlax-get obj 'Coordinates)
      ); setq
      (if (equal (assoc 10 edata) (assoc 10 (reverse edata)) 1e-4) 
        (vlax-put obj 'Coordinates (reverse (cddr (reverse coords))))
      ); if
    ); repeat
  ); if
  (princ)
); defun
Kent Cooper, AIA
Message 12 of 35


@Kent1Cooper  a écrit :


For AutoCAD 2020 that I have here, that is not a problem -- it Extrudes those successfully.  But if that isn't allowed in some versions, here's a routine to fix that kind of Polyline:


@Kent1Cooper 

Hi Kent

It's not extrude that's the problem, but the selection by polygonal window in the link given by ronjonp.
With the example drawing provided, with the figure on the left for example.

 

 

(ssget "_WP" '((3668.35 43466.6 0.0) (3970.35 43884.6 0.0) (7490.35 42147.6 0.0) (7385.35 41148.6 0.0) (20087.4 34705.6 0.0) (14571.4 23217.6 0.0) (-16185.6 39319.6 0.0) (-8756.65 51216.6 0.0) (-8756.65 51216.6 0.0)) '((0 . "TEXT")))

 

 


returns nothing, but

 

 

(ssget "_WP" '((3668.35 43466.6 0.0) (3970.35 43884.6 0.0) (7490.35 42147.6 0.0) (7385.35 41148.6 0.0) (20087.4 34705.6 0.0) (14571.4 23217.6 0.0) (-16185.6 39319.6 0.0) (-8756.65 51216.6 0.0) ) '((0 . "TEXT")))

 

 


Effectively returns a selection (after removing the duplicate at the end)

Message 13 of 35

thank you for good answer .

sorry for many ask .

i tested again 

but

some is  success

some is fail

 

i have 2 problem 

 a. extrude problem 

 b. extrude speed  (  this attathed file is   small part , i  use more big size , so i need fast code )

 

 

sorry for many ask again , 

really sorry 

Message 14 of 35

With this code of ronjonp modified, don't work's?

(defun c:foo (/ i n p s sp)
  ;; RJP » 2021-02-12
  (if (setq s (ssget ":L" '((0 . "*POLYLINE"))))
    (progn ;(setq sp (vlax-ename->vla-object (cdr (assoc 330 (entget (ssname s 0))))))
	   (vl-cmdf "_.UNDO" "_Begin")
	   (setvar 'cmdecho 0)
	   (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	     (setq p nil)
	     (repeat (fix (setq i (vlax-curve-getendparam e)))
	       (setq p (cons (vlax-curve-getpointatparam e i) p))
	       (setq i (1- i))
	     )
	     (if (equal (cadr (reverse p)) (last p) 1E-8)
	       (setq p (cdr (reverse p)))
	     )
	     (if (and (setq i (ssget "_CP" p '((0 . "TEXT"))))
		      (> (setq n (atof (cdr (assoc 1 (entget (setq i (ssname i 0))))))) 0)
		 )
	       ;; Vl extrusion is not as editable?
	       (progn ;; (setq r (car (vlax-invoke sp 'addregion (list (vlax-ename->vla-object e)))))
		      ;; (vlax-invoke sp 'addextrudedsolid r (* 3 n) 0.)
		      (vl-catch-all-apply 'vl-cmdf (list "_.extrude" e "" (* 3 n)))
	       )
	     )
	   )
	   (vl-cmdf "_.UNDO" "_End")
	   (setvar 'cmdecho 1)
    )
  )
  (princ)
)
Message 15 of 35

Yes
I use cad 2014
But that did not work
Message 16 of 35


@anycganycgJ8A6A  a écrit :
Yes
I use cad 2014
But that did not work

And in this simplest form (may take 5-10 minutes, be patient)

(defun c:foo (/ i n p s sp)
  ;; RJP » 2021-02-12
  (if (setq s (ssget ":L" '((0 . "*POLYLINE"))))
    (progn
	   (setvar 'cmdecho 0)
	   (command "_.UNDO" "_Begin")
	   (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	     (setq p nil)
	     (repeat (fix (setq i (vlax-curve-getendparam e)))
	       (setq p (cons (vlax-curve-getpointatparam e i) p))
	       (setq i (1- i))
	     )
	     (if (equal (cadr (reverse p)) (last p) 1E-8)
	       (setq p (cdr (reverse p)))
	     )
	     (if (and (setq i (ssget "_CP" p '((0 . "TEXT"))))
		      (> (setq n (atof (cdr (assoc 1 (entget (setq i (ssname i 0))))))) 0)
		 )
		      (command "_.extrude" e "" (* 3 n)))
	   )
	   (command "_.UNDO" "_End")
	   (setvar 'cmdecho 1)
    )
  )
  (princ)
)
Message 17 of 35

Really thank you for good answer
I use 100,000 objects
Very slow ~
Command extrude <-slow
Vlax addextrude is <- more fast
Very fast way ?
Message 18 of 35
ronjonp
in reply to: anycganycgJ8A6A


@anycganycgJ8A6A wrote:
Really thank you for good answer
I use 100,000 objects
Very slow ~
Command extrude <-slow
Vlax addextrude is <- more fast
Very fast way ?

Simply uncomment the lines in green then comment out the vl-cmdf line:

ronjonp_0-1660237290624.png

 

Message 19 of 35


@anycganycgJ8A6A  a écrit :
Really thank you for good answer
I use 100,000 objects
Very slow ~
Command extrude <-slow
Vlax addextrude is <- more fast
Very fast way ?

It's not extruding that's long, but text selection by polygonal window.
I think that initially it would have made more sense to attach an xdata to the lwpolyline entity instead of a text approximately in the center, it would have been much more reliable...
The processing could have been much faster because it no longer required a graphic selection in the lisp.
Moreover if you could not have the complete drawing with a wheel zoom, the procedure would have ignored the elements outside the maximum window.

Message 20 of 35

thank you  for good advice

really really thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta