Jump to content

Polyline elevation and LISP...


ramis

Recommended Posts

Hi everybody,

i've got (again) a little problem with lisp... i want to selection the polyline of my drawing thanks to their elevation to put them on a specific layer (all the polylines with elevation at 0.0 are on a layer, all the polylines with elevation at -2.0 are on an other layer...) but everytime my selection is said nil...

the lisp sentence that i used is :

(setq contour2 (ssget "_x" '((0 . "POLYLINE")(30 . -2.0))))

The problem is for the (30 . -2.0) because without it, my selection is not nil. I've open a dxf to see for a specific polyline how the elevation is coded and it seems to be with 30...

i'm using autoCAD 2006...

thanks,

ramis

Link to comment
Share on other sites

thanks for your help fuccaro but it doesn't work... i think that the problem really comes from the (30 . 0.0). i don't understand it's existing on my dxf file: i have note the handle of my polyline and for it, i've got 0.0 at 30... but in when i execute my lisp, it seems to ignore it...

Link to comment
Share on other sites

I think the dxf code for the elevation of a polyline is 38; at least it is for a lwpolyline. Dxf code 30 is for the z value of the insert/start/center point of a line, point, circle, arc...according to the reference I have.

Link to comment
Share on other sites

thank you for your help... you're right... :)

the code for the elevation of a polyline is 38!!! now, my script is working... but i don't understand why in my dxf file for the description of the polylines i have the elevation at 30 and i don't have a 38 in my file... an mystery of the dxf file!!! but maybe it's not a thing coded in the dxf file. it's generated by autoCAD when a file is opened...

Link to comment
Share on other sites

May be you use "LWPOLYLINES" (elevation DXF = 38 ) not "POLYLINES"? Do (entget(car(entsel))) in command line and look entity type. I write to you short code it can work as with LWPOLYLINES as POLYLINES (if you change DXF codes in filter).

 

(defun c:elevl(/ eleVal polySet layLst errCnt
       lName layCol layErr errCnt filLst)
 (vl-load-com)
 (if
   (setq eleVal
   (getreal "\nSpecify elevation to select polylines: "))
   (progn
     (setq filLst(list '(0 . "LWPOLYLINE")(cons 38 eleVal)))
     (if
(setq polySet
       (ssget "_X" filLst))
(progn
  (princ(strcat(itoa(sslength polyset)) " polylines found. "))
  (sssetfirst nil polySet)
  (setq layLst 
	 (mapcar 'vlax-ename->vla-object
	    (vl-remove-if 'listp
                       (mapcar 'cadr(ssnamex polySet))))
	errCnt 0
	); end setq
  (if
    (/= ""(setq lName
	     (getstring T "\nSpecify layer to move to: ")))
    (progn
      (if
	(not(tblsearch "LAYER" lName))
	(progn
	  (setq layCol
		 (vla-get-Layers
		   (vla-get-ActiveDocument
		     (vlax-get-acad-object))))
	  (if
	     (vl-catch-all-error-p
	       (vl-catch-all-apply
		  'vla-Add (list layCol lName)))
	    (progn
	       (setq layErr T)
	       (princ "\nCan't create layer with this name ")
	      ); end progn
	    ); end if
	  ); end progn
	); end if
      (if(not layErr)
	(progn
	  (foreach itm layLst
	    (if
	      (vl-catch-all-error-p
		(vl-catch-all-apply
		  'vla-put-layer (list itm lName)))
	      (setq errCnt(1+ errCnt))
	      ); end if
	    ); end foreach
	  ); end progn
	); end if
      ); end progn
    ); end if
         (princ(strcat "\n"(itoa(-(sslength polySet)errCnt))
	       " now moved to layer '" lName "' "))
         (if(/= 0 errCnt)
    (princ(strcat (itoa errCnt) " were on locked layer! "))
   ); end if
  ); end progn
(princ "\nNothing polylines with this elevation ")
); end if
     ); end progn
   ); end if
 (princ)
 ); end of c:elevl

Link to comment
Share on other sites

Thank you for your code ASMI. it's very amazing to see how easy it seems to be for you to write this LISP code... and i like the term "short". But I'll use it... I will try to understand it and then to adapt it. indeed, I assign manually in my code the name of the layer and then i do my filter to select the polyline with the wanted elevation and i put them on the layer. but this works here because i know that the elevation of my polylines are 0,2,4,6,... but know, i will try to adapt your code to check for all the polyline the different elevation and then to separate them on different layers... not easy (for me...:D )

 

thanks again for all the time you spend working on this code

ramis

Link to comment
Share on other sites

Small error was in my code, copy it agan please :(

If you need help you can ask me. Do you want automaticaly put polylines to layers corresponds to elevations, for example "Elevation -2", "Elevation 43" etc. ? It not difficult task.

Link to comment
Share on other sites

thank you ASMI :)!! yes, that's what i want to do... eventhough i don't know the elevations of the polylines of my drawing, i want to separate them on different layers... and if the name of the layer could contain the elevation, it will be perfect.:D

thank you for help ASMI... if i don't know how to write the LISP fonction, i will ask help but first i want to understand your code and to try by myself to write it...:D

ps: i imagine that it's easy for you but i work with autoCAD since the 02 May... so i am really a beginner!!!!!!

Link to comment
Share on other sites

i work with autoCAD since the 02 May... so i am really a beginner!!!!!!

 

Very similar on me. I have started to study AutoLISP after 1 month of work in AutoCAD. It was approximately 4 years ago...

 

first i want to understand your code and to try by myself to write it

 

Ok. Because that is able to write programs who writes programs.

Link to comment
Share on other sites

  • 10 years later...

Hi gentlemen,

I need lisp, which is automatically prepare new layer in every different elevation which opens in a new layer. Layer should be appropriate with the name of elevation e.g : name of elevation is "+15.5" and layer name should be the same name

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