Autolisp script for "planesurf" command

Autolisp script for "planesurf" command

ondrej.vitekV2NU6
Explorer Explorer
1,483 Views
6 Replies
Message 1 of 7

Autolisp script for "planesurf" command

ondrej.vitekV2NU6
Explorer
Explorer

Hello,

I am a beginner in autolisp and i would like to create a script/routine for creating plane surfaces. I think I've come close, but something is wrong in it, so any help would be greatly appreciated.

 

I would like the user to select number of entities/objects - certain number of closed polylines. Each of these polylines is in different layer. For every polyline from the selection, i would like to create plane surface (planesurf command). But these surfaces will be in active layer and i would like them in same layer as the polyline is.

 

The desired steps of the script:
1) prompt user to do a selection of polylines.
2) cycle through these
3) each step of the loop would contain:
Get the name of polyline's layer
Change active layer to the layer of polyline
Select that polyline
perform command "planesurf"
4) repeat the cycle for all polylines of the selection.

 

My code, which doesn't work properly:

(setq ss1 (ssget)) 
(repeat (setq i (sslength ss1))
      (setq list1 (cons (ssname ss1 (setq i (1- i))) list1))
      )
(setq ss1 nil)

(foreach n list1 (progn
    (setq layer (cdr (assoc 8 (entget n))))
    (setq selset (ssadd n))
    (sssetfirst nil selset)
    (setvar "CLAYER" layer)
    (command "_planesurf" "")

    (setq selset nil)
    )
)

 

The script now says "error - function cancelled", prompts user for selection for second time and creates plane surfaces in all polylines but the surfaces are all in one layer.

 

Attached is my testing file, unfortunately i dont have the final file yet. But it will be the same, just more layers and more polylines. In the attached file for testing, there are only 3 polylines in 3 layers starting with "_" 

 

Thank you in advance

0 Likes
Accepted solutions (1)
1,484 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

@ondrej.vitekV2NU6 wrote:

Hello,

I am a beginner in autolisp ... nice attept! keep going... but why do you convert ss into list?

...

The desired steps of the script:
1) prompt user to do a selection of polylines. ok
2) cycle through these sure
3) each step of the loop would contain:
Get the name of polyline's layer done, but later
Change active layer to the layer of polyline no, no, better don't mess with clayer. Create an object and change its layer afterwards.
Select that polyline
perform command "planesurf" sure
4) repeat the cycle for all polylines of the selection. just once, not twice

 

 


 

(defun c:PlanesurfObjects ( / s i e)
  (if (setq s (ssget '((0 . "LWPOLYLINE"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (command "_.planesurf" "_object" e ""
	       "_.chprop" "_last" "" "_layer" (cdr (assoc 8 (entget e))) "")))
  (princ)
  )

 

Message 3 of 7

ondrej.vitekV2NU6
Explorer
Explorer

Amazing! Thank you very much for the solution. Works great!

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

You're welcome. If you have any questions just ask. 

 

BTW Scripts and AutoLISPs are 2 different things. A script is just a list of AutoCAD's commands that you will run through the command line (*.scr file). Scripts are also applicable to LTs. AutoLISP is much more powerful and that's what you have written.

Message 5 of 7

pbejse
Mentor
Mentor

@ondrej.vitekV2NU6 wrote:

Hello,

I am a beginner in autolisp and i would like to create a script/routine for creating plane surfaces. I think I've come close, but something is wrong in it, so any help would be greatly appreciated.

 


Like @ВeekeeCZ  said, Nice attempt.

Notes on your code, since you already have a solution.

(setq ss1 (ssget))
;;	(setq ssl (ssget '((0 . "LWPOLYLINE"))));<--include a filter

(repeat (setq i (sslength ss1))
      (setq list1 (cons (ssname ss1 (setq i (1- i))) list1))
      )
		;	 see beow comment on foreach

(setq ss1 nil)	;	<-- not required 
		

(foreach 	; 	okay to use if you want your selection in a particular order based on 
       n list1	;	properties of the selected objects for example, otherwise process the objects within
      		;	repeat loop
       
(progn			;	a wrapper is not required here
           
(setq layer (cdr (assoc 8 (entget n))))        
            
(setq selset (ssadd n))	; I'm guessing you wanted to "select first"	
(sssetfirst nil selset)	; for _planesurf is why you include a selection set
        		; use _object option within _plansurf command
        	
(setvar "CLAYER" layer)	; This is okay, but you may have to include a callback to the original
        		; clayer setting, you can do this via *error* function        			
        
(command "_planesurf" ""); use _object option within _plansurf command

(setq selset nil)	; not really required if 
            )		; end of progn : not required 
      )

 HTH

 

Message 6 of 7

ondrej.vitekV2NU6
Explorer
Explorer

Ok, thank you!

0 Likes
Message 7 of 7

ondrej.vitekV2NU6
Explorer
Explorer

Thank you for your comments! Much appreciated

0 Likes