Jump to content

Recommended Posts

Posted

Hello, I recently discovered the potential in acad with lisps, and first of all I want to thank all the people sharing their knowledge (specific thanks to Tharwat and GC gile)! I am completely ignorant regarding what seems like programming here, but I am very willing to try and learn (allready succeeded in changing a parameter in a lisp all by myself!)

The facts are: I have lots of closed 2d polylines (or lwpolylines, doesn't really matter because I have learned how to turn my polys into lwpolys). I have to extract their area, layer and coordinates, in a way that each polyline's data can be identified in the resulting file.

I started by researching a way to automatically name the polylines, not much luck, so I am determined to enter numbers manually in the hyperlink field for each polyline.

I have also found a lisp that extracts hyperlink, layer and area for multiple polys at once, which is a great first step (as a newbie I am not sure if I can post the link here).

What now remains is to extract each poly’s coordinates together with its hyperlink. Do you think it is doable to invent a routine and achieve this for many polylines at once?

Alternatively I will have to list and copy paste the coords for each polyline separately... for 400 polylines ... and then again in another similar dwg... etc.

Sorry for the large thread, I hope I explained properly – and sorry if the answer already exists somewhere, I did my best to find it but didn’t (I did find quite some lisps to export coords, without separation per polyline and without hyperlink. Maybe someone experienced could alter these to include the extra data, but this is not my case…)

Many thanks in advance to all the helpfull inlightened people here,

Maria

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • mariarfd

    10

  • hanhphuc

    6

  • BIGAL

    3

  • Tharwat

    3

Posted (edited)

I started by researching a way to automatically name the polylines, not much luck, so I am determined to enter numbers manually in the hyperlink field for each polyline.

 

Hi, not really sure what do you mean "name the polyline"?

 

i prefer handle which is unique hex,

so you don't need manually put hyperlink?

 

some examples to retrieve vertex of

LWPOLYLINE

 

for multiple loop repeat , while , foreach , mapcar functions

In this example using repeat , then prints out every polyline info.

 

This is vlisp method , it's 'get properties' method syntax easier to understand

([color="blue"]vl-load-com[/color]) [color="green"]; initialization [/color]

(defun c:test (/ lst s i [color="red"]en obj[/color])
 (and (setq   s	(ssget	[color="purple"]"X"[/color] [color="green"]; selection mode : X = extended database [/color]
		'((0 . [color="purple"]"LWPOLYLINE"[/color]) [color="green"]; object Name[/color]
                         (-4 . "&=") [color="green"]; bit coded[/color]
		  (70 . 1) [color="green"]; polyline is closed[/color]
		  (90 . 4) [color="green"]; accept only 4 corners[/color]
		  (8 . [color="purple"]"*"[/color]) [color="green"]; Filter Layer name , to be modified example "Layer1"[/color]
                         (410 . "model") [color="green"]; model space[/color]
		  )
		) 
     ) 
      ([color="blue"]repeat[/color] (setq i (sslength s))  [color="green"]; loop counter selection set[/color]
 (setq en  (ssname s (setq i (1- i))) [color="green"]; ename by decremental selection set[/color]
       obj (vlax-ename->vla-object en) [color="green"]; converts entity to vla-object[/color]
       lst (mapcar ''((x) (vlax-get obj x)) [color="green"]; get properties method[/color]
			 '(Handle	[color="green"]; handle unique ID[/color]	
			   Area		[color="green"]; area[/color]
                                  Layer        [color="green"]; layer[/color]
			   Coordinates	[color="green"]; vertex array X Y X Y X Y ...[/color]
			   ))
       )
 (terpri) [color="green"]; prints new line[/color]
 (princ lst) [color="green"]; output[/color]
 ) 
      )
 (textpage) [color="green"]; activate full text page[/color]
 (princ)[color="green"] ; suppress exit quietly[/color]
 ) ;_ end of defun

Edited by hanhphuc
comments added, vl-load-com , update URL link
Posted

Hanhphuc thank you very much for your time and sharing your knowledge! I will try to study in depth the information you provided and hope you can come back later and give some more help if I do not understand something specific...!

Again, gratefull for your answer,

Maria

Posted
Hanhphuc thank you very much for your time and sharing your knowledge! I will try to study in depth the information you provided and hope you can come back later and give some more help if I do not understand something specific...!

Again, gratefull for your answer,

Maria

no worries, if i'm absent others volunteers will jump in to assist as long as you are always active & willing to learn ;)

Just name few active gurus Lee Mac, Tharwat, BIGAL etc..

 

i've updated the reference link in my previous post, which are few autolisp examples (to get coordinates of vertices) by other members.

 

 

p/s: added (vl-load-com)

Posted
p/s: added (vl-load-com)

 

Hi,

 

Just wondering why are you usually taking the way to Vlisp functions since you can get the job done more smoothly with DXF codes ;) ?

Posted (edited)
Hi,

 

Just wondering why are you usually taking the way to Vlisp functions since you can get the job done more smoothly with DXF codes ;) ?

 

hi Tharwat thanks for suggestion i did provide link for autoliso dxf :)

The OP is willing to learn, it's ok your post dxf code is welcome!

 

IMO perhaps i think vlisp syntax is easier for newbie to learn ?

 

vla-get-layer than dxf

(cdr(assoc 8 (entget en)))

?

 

what's his/her preference? :)

my $0.02

 

vlisp

 (vlax-get object 'coordinates) 

 

autolisp dxf


(defun getpoly (en / l enx dxf)
 (defun dxf (i en) (cdr (assoc i (entget en))))
 (cond	((= (dxf 0 en) "POLYLINE") [color="green"];3D polyline[/color]
 (while (/= "SEQEND" (dxf 0 (setq en (entnext en)))) (setq l (cons (dxf 10 en) l)))
 )
((= (dxf 0 en) "LWPOLYLINE") [color="green"];2D polyline[/color]
 (setq enx (entget en))
 (while	(setq enx (member (assoc 10 enx) enx))
   (setq l   (cons (cdar enx) l)
	 enx (cdr enx)
	 ) 
   )
 )
(t (setq l (list (dxf 10 en) ))) [color="green"]; optional return coordinates other than polyline[/color]
) 
 (reverse l)
 )

 

test

(setq en (car(entsel "\nPick polyline.." )))
(getpoly en )

Edited by hanhphuc
Posted

thank you Hanhphuc, it seems like when you where posting your update for vl-load-com, I was simultaneously researching online the error "No function definition: vlax-ename->vla-object" and came up with the same update -worked perfectly! And so did your code!

Sooo greatfull... This does exactly what I needed, and will save me a lot of garbage work, both now and in the future!!

 

will try to do some minor changes and maybe come back for a little bit more help...!

 

ps: It is unbelievable how much good energy can be sent, you made me happy today! I wish I could repay you the favour, but since I cannot I will try to help more often a complete stranger, like you do for me!

Posted

mmm, I accidentally found some lisps online (researching for options to manipulate data from large dwgs in excel), found them extremely usefull (like a new world) and kind of liked their way of thought... That was like a year ago. Since then I have read some basic rules, but cannot write something new by myself yet (I have lots of work plus a 2 year old..!) I am starting to try some modifications on ready codes though, I like it very much! I do not think I have seen a dxf code so far, I will try and research that too , now that you mentioned it. I do not declare myself as a master in autocad, I learnt some very basic stuff in university (r14, that was a long time ago) and since then I can say I got adequate by working, but still it has a lot of possibilities I do not have mastered yet.

Posted

you are welcome, i'm same as you like Tharwat as always is my helping friend ;).

 

i helped 70% but the rest 30% is task for you to solve how to populate the coordinates (output by vlisp), since both 2D & 3D coordinates are in single array list

you need to differentiate their proper format otherwise you'll mess up

'(X Y X Y X Y X Y)  - >  '((X Y)(X Y)(X Y)(X Y)) [color="green"]; 2D[/color]
'(X Y Z X Y Z X Y Z)  - > '((X Y Z)(X Y Z)(X Y Z)) [color="green"];3D[/color]

 

good luck

Posted

You were even more kind to take the time and explain next to every step, what it means in english. So now I have: 0,70,90,8 and 410 meanings in english. Could you please direct me where I should look to find a complete (ctr+f able) list of what all the other numbers stand for? or this is not the way it works? I try to change / add some parameters in your code and would be greatfull if there was such a list... Maybe this is a stupid question and this exists in vlsp editor in autocad or something, but I cannot find it not even online, maybe I am not searching the proper way.

Thank you again,

maria

Posted

sorry, I think I found it - I searched for vlsp syntax reference...

Posted

thank you Tharwat, very nice! I am a little confused though, are these codes the same for dxf that you mentioned and lsp?

Posted

Try this routine to retrieve the DXF of the selected object / entity.

 

(defun c:dxf (/ ent)
 (if (setq ent (car (entsel "\n-> Select an entity : ")))
   (progn (foreach x (entget ent '("*")) (print x)) (textscr))
   )
 (princ)
 )

Posted
You were even more kind to take the time and explain next to every step, what it means in english. So now I have: 0,70,90,8 and 410 meanings in english. Could you please direct me where I should look to find a complete (ctr+f able) list of what all the other numbers stand for? or this is not the way it works? I try to change / add some parameters in your code and would be greatfull if there was such a list... Maybe this is a stupid question and this exists in vlsp editor in autocad or something, but I cannot find it not even online, maybe I am not searching the proper way.

Thank you again,

maria

 

dxf Common Group Codes for Entities then polyline etc..

 

Thanks Tharwat's link as well :)

 

FWIW, i hope vlisp methods & propertires are more 'readable' for newbie

(setq en (car(entsel)))
(vlax-dump-object (vlax-ename->vla-object en) [color="blue"]t[/color])

 

 

Here's example comparison dxf & VL:

If the extrusion of entity (normal) other than '(210 0. 0. 1.), by dxf

(cdr(assoc 10 (entget en)))

, you maybe need to transform ocs to wcs as well.

whereas by VL activeX vla-get-coordinates method , it takes this 'normal' into account.

 

however learning both is an advantage :)

Posted

You will find that lots of code has a mix of VL and use of dxf codes, I know I have some code that uses entmake dxf to make a block but rest of code is VL.

 

 

I will try to find co-ordinates code it uses the object type to work out if it supports 2d or 3d ie divide the 'co-ordinates list by 2 or 3 I think its at home.

Posted

Hello again, so I have been trying to "translate" the code and understand it as a first step, most of it was not as hard as I thought, except if I got it all wrong! I used word because it helped me visualize it, i use this only for translation and will not try to load anything from this word file. Please review my file and give some more hints!

 

I tried

-succesfully to add length in vlax-get

-unsuccesfully to change (90. 4) to (90. anyBiggerNumber)

-unsuccesfully to competely delete (90.4) parameter hoping to get all coordinates of the entity, and then to ad something like (x) in vlax-get coordinates or (coordinates (x)) hoping that x will mean all (and also tried multiple other stuff which resulted in errors returned initially and finally just the defun returned without any list at all... probably I havent understood the syntax and kept arbitrarily writing stupid things! that must be funny to you all! ... but it s my first time.) Does this has to do something with other default settings , or just I did'nt do it right?

 

So now I did at least add the length which I need, which was just easy and common sence, and I have 2 problems:

-I need all the coordinates , please point me at some direction if you think I can do it by myself

-I need better precision in the coordinates results. Regarding this I researched and found that in the lisp the precision is max, but in the print it comes out smaller, and have tried to apply rtos (you must be laughing reading this) , luprec and much more, but probably not in the right way , just a longshot. This resulted in messing the drawing itsself, luckily that was a test drawing. I am laughing myself now. Please give me a hint regarding that matter or if it is too advanced, could you give a lot more help?

Thank you in advance very much for your time,

maria

translate in english.docx

Posted

Thank you very much bigal, I would appreciate that very much!

Posted

Here's another to get both dxf and vla properties for an object:

(defun c:dxflist (/ e)
 (cond	((setq e (car (entsel "\nPick something to see data: ")))
 (mapcar 'print (entget e '("*")))
 (vlax-dump-Object (vlax-ename->vla-object e) t)
 (textscr)
)
 )
 (princ)
)(vl-load-com)

 

There is also THIS.

Posted

localisinq variables

 


[color="green"];structure of routine, define a function - defun,defun-q[/color]
([color="blue"]defun[/color] [b]sym[/b] ([arguments] [/ variables...])
 expr...
 )

[color="green"];example [/color]
(defun [b]test[/b] ( / [color="red"]lst s i en obj[/color] ) [color="green"]; localized variables
[/color]
 [color="green"];*error* handler   [/color]

 (setq [color="red"]s[/color] (ssget)) [color="green"]; s = symbol [/color]
[color="green"]  ;... 
 ;... etc.[/color]
 
 (princ)

 ) 

[color="green"]
;calling function in the command line
;command: (test) 
;command: test  ; [i][color="red"]Unknown command "TEST".  Press F1 for help. [/color][/i]   [/color]

      
[color="darkgreen"];symbol with prefix "[b]C:[/b]" [/color]      
(defun [b]c:test[/b] ( / [color="red"]lst s i en obj[/color] )[color="green"] ; localized variables[/color]
[color="green"]; ... etc. [/color]
(princ)  ) 
      
[color="green"];both ok 
;command: (c:test)
;command: test[/color]


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