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

Replace similiar objects with a new object

12 REPLIES 12
Reply
Message 1 of 13
cadsys08
328 Views, 12 Replies

Replace similiar objects with a new object

I have this dxf that has a bunch of points....only the points aren't really points; they are a series of tiny lines that form a little circle. So i have tons of these circles/closed polylines that need to be converted to points. I have been searching the forms but no luck. Any help would greatly be appreciatted.
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: cadsys08

cadsys08 wrote:
> I have this dxf that has a bunch of points....only the points aren't
> really points; they are a series of tiny lines that form a little
> circle. So i have tons of these circles/closed polylines that need to
> be converted to points. I have been searching the forms but no luck.
> Any help would greatly be appreciatted.
Whether they are lots of little lines or closed polylines, you can
determine their center(close enough, anyhow) by taking the average value
of the (assoc 10) codes of their vertices, put a point there, and erase
the original stuff.

So the question is, how many of these pseudo-points are there? A couple
of dozen you can do by selecting the lines by window for each point, but
a couple of hundred would get right tedious. Maybe get them all on a
layer of their own, figure out how to turn them into closed polylines,
and then process all the resulting polylines as above.

-Bill
Message 3 of 13
Anonymous
in reply to: cadsys08

Can you post a sample dwg of what you have? I had to do something similar a
few years back with a few thousand dwgs so I have a few lisp that may work
for you but may need adjusting.
Message 4 of 13
stevor
in reply to: cadsys08

A common problem that can usually be automated, like the Auto in Autocad.
The programming for a geometry recognition would go something like:
1. search for the appropriate size line by ssget or by stepping thru the entity dbase.
2. search about its end for lie sized lines until a loop is found.
3. estimate a center in the mention manor, or the equivalent.
4. create the new point
5. delete or change the layer of the lines
S
Message 5 of 13
stevor
in reply to: cadsys08

A common problem that can usually be automated, like the Auto in Autocad.
The programming for a geometry recognition would go something like:
1. search for the appropriate size line by ssget or by stepping thru the entity dbase.
2. search about its end for lie sized lines until a loop is found.
3. estimate a center in the mention manor, or the equivalent.
4. create the new point
5. delete or change the layer of the lines
S
Message 6 of 13
cadsys08
in reply to: cadsys08

Although I have programming experience, I am still new to LISP....so work with me.....

I attached the file........ this is the original so you will have to make polylines and close the "lil circles"....easy enough

The closest thing I can find online is this, but I need to get the points going for the center of the "lil circles":

This puts a selected object where ever there are points.......

(defun c:Rp()
(setq ss (ssget "x" (list (cons 0 "points"))))
(setq inc 0)
(setq obj (car (entsel "\nSelect an object to locate at each point: ")))
(setq orgpnt (cdr (assoc '10 (entget obj))))
(while (setq node (ssname ss inc)))
(setq topnt (cdr (assoc '10 (entget node))))
(command "copy" obj "" orgpnt topnt)
(setq inc (1+ inc)))
(princ "\nDone")
)

I was using this because ultimately I would like to be able to copy a "station symbol"(object) to each of these points.

Edited by: cadsys08 on Oct 16, 2008 4:46 PM Edited by: cadsys08 on Oct 16, 2008 6:47 PM
Message 7 of 13
Anonymous
in reply to: cadsys08


Can't download the attachment for some reason.
Message 8 of 13
Anonymous
in reply to: cadsys08


Hi cadsys08,

 

I've  downloladed the drawing and I was able
to select all the polylines and PEDIT all of them in one shot, using a fuzz
factor of 0.0000001 for the JOIN option. This resulted in 282 closed
polylines. Now, I assume that it's kind of easy to replace each of them one by
one by a circle using 3 vertices from each polyline, delete the
polyline and then adding a point in the center of the circle and then
removing the circle.

 

Try to do this by your self, and if you have
problems, come back.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Although
I have programming experience, I am still new to LISP....so work with me.....
I attached the file........ this is the original so you will have to make
polylines and close the "lil circles"....easy enough The closest thing I can
find online is this, but I need to get the points going for the center of the
"lil circles": This puts a selected object where ever there are points.......
(defun c:Rp() (setq ss (ssget "x" (list (cons 0 "points")))) (setq inc 0)
(setq obj (car (entsel "\nSelect an object to locate at each point: "))) (setq
orgpnt (cdr (assoc '10 (entget obj)))) (while (setq node (ssname ss inc)))
(setq topnt (cdr (assoc '10 (entget node)))) (command "copy" obj "" orgpnt
topnt) (setq inc (1+ inc))) (princ "\nDone") ) I was using this because
ultimately I would like to be able to copy a "station symbol"(object) to each
of these points. Edited by: cadsys08 on Oct 16, 2008 4:46 PM
Message 9 of 13
cadsys08
in reply to: cadsys08

Try this file.......

Yeah I figured out that using a 2 pnt circle and click opposing verticies makes an nice centered circle....then snap a point to center of circle, then delete polyline. I can easily make a macro to do this, but sometimes the file might have hundreds, maybe thousands of "points"....I need to be able to do this operation to a selection set...not one at a time.

I have a line plot associated with these points.....it might be easier to write LISP to put circles(objects) at each endpoint of the lines.....just a thought.

Edited by: cadsys08 on Oct 17, 2008 12:30 AM

I was able to use the code to snab the objects to the ends of the lines by simply changing (setq ss (ssget "x" (list (cons 0 "points")))) to (setq ss (ssget "x" (list (cons 0 "line")))). Works like a champ, except for it seems to repeat the process 5 times.....so i end up having to use overkill command to go back and clean up the overlapping objects(no big deal).

Still would be nice if someone could refine this code.......ultimately what would be nice would be like a find and replace for objects.

Edited by: cadsys08 on Oct 17, 2008 1:26 AM
Message 10 of 13
devitg
in reply to: cadsys08

As all are14 sided poly , make a selection set ,

(setq all-poly-ss (ssget "x" '( ( 0 . "lw*") (8 . "MARKS") )))


and convert each poly-ent to a poly obj
by
(vl-load-com)

(setq acad* (vlax-get-acad-object)) ;_ ACAD program
(setq adoc (vla-get-activedocument acad*)) ;_ the current

(vla-get-activeselectionset adoc)

then

by

(setq end-par (vlax-curve-getEndParam poly-obj))
(setq p1 (vlax-curve-getPointAtParam poly-obj 0))
(setq p2 (vlax-curve-getPointAtParam poly-obj (/ end-par 2.0)))


get the mid point

(setq cent (mapcar '* '(0.5 0.5 0.5) (mapcar '+ p1 p2)))

now you can make the point , and erase the poly .

Hope it is clear .












Message 11 of 13
Anonymous
in reply to: cadsys08


Hi again cadsys08,

 

Based on the suggestion made by devitg, here is a
function that will replace the initial entities with points. From your
drawing, it comes out that the "li'l circles" are made up of
small LINE segments. So I PEDIT them first, then I get some representative
points on the new polylines and then I place a point on the determined cennter,
erasing the polyline in the end. The JOIN part takes a little longer with large
number of "li'l circles" so you have to be patient 🙂 If you need, you can
define a command to be used with this function (see the code
below).



HTH

 


size=2>;;;=================================================

(defun C:SPT ()(SubstPoints)(princ))


size=2>;;;=================================================

(defun SubstPoints ( /


size=2>                             
activedocument


size=2>                             
old_cmdecho


size=2>                             
all_lines


size=2>                             
all_polys


size=2>                             
center


size=2>                          
)

 

  (vl-load-com)

 

  (setq activedocument (vla-get-activedocument
(vlax-get-acad-object)))

 

 (setq old_cmdecho (getvar
'cmdecho))

 (setvar 'cmdecho 0)



  (setq all_lines (ssget '((0 . "LINE")(8 .
"MARKS"))))
  (command "_.pedit" "_m" all_lines "" "_j" 0.0000001
"")

  
  (ssget "X" '((0 .
"LWPOLYLINE")(8 . "MARKS")))

  (setq all_polys (vla-get-activeselectionset
activedocument))

 

  (setvar 'pdmode 34)

  (setvar 'pdsize
-1)
  
  (vlax-for poly all_polys

face=Arial size=2>
 

    (setq center
      (mapcar
'* '(0.5 0.5 0.5)
        (mapcar
'+
         
(vlax-curve-getPointAtParam poly
0)
         
(vlax-curve-getPointAtParam
poly
            (/
(vlax-curve-getEndParam poly)
2.0)
         
)
       
)
      )
   
)
   
   
(vla-addpoint
      (vla-get-modelspace
activedocument)
      (vlax-3d-point (trans center 0
1))
    )
   
   
(vla-delete poly)

  )


  (setvar 'cmdecho
old_cmdecho)
  
  (princ)
)


size=2>;;;=====================================================

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Try
this file....... Yeah I figured out that using a 2 pnt circle and click
opposing verticies makes an nice centered circle....then snap a point to
center of circle, then delete polyline. I can easily make a macro to do this,
but sometimes the file might have hundreds, maybe thousands of "points"....I
need to be able to do this operation to a selection set...not one at a time. I
have a line plot associated with these points.....it might be easier to write
LISP to put circles(objects) at each endpoint of the lines.....just a thought.
Edited by: cadsys08 on Oct 17, 2008 12:30 AM I was able to use the code to
snab the objects to the ends of the lines by simply changing (setq ss (ssget
"x" (list (cons 0 "points")))) to (setq ss (ssget "x" (list (cons 0
"line")))). Works like a champ, except for it seems to repeat the process 5
times.....so i end up having to use overkill command to go back and clean up
the overlapping objects(no big deal). Still would be nice if someone could
refine this code.......ultimately what would be nice would be like a find and
replace for objects. Edited by: cadsys08 on Oct 17, 2008 1:26 AM
Message 12 of 13
cadsys08
in reply to: cadsys08

WOW! Thanks guys! that code is way over my head...I would have never figured it out on my own.


I will get back to you soon and let you know how it works out.



Thanks again!
Message 13 of 13
Anonymous
in reply to: cadsys08


I made some tests and I've realised that because
the circles are aproximated by line segments, the first solution places the
points slightly "out of tune", i.e. shifted from the center of a real circle
that would replace the initial "circle like" shape. So if you need greater
accuracy, here is a modified version, that creates a circle over the initial
shape, places a point in the center of the new circle, then erases the circle
and the initial shape.

 


size=2>;;;=================================================

(defun SubstPoints (
/
                             
activedocument
                             
old_cmdecho
                             
all_lines
                             
all_polys
                             
pt1
                             
pt2
                             
pt3
                             
circle
                            )
 
 
(vl-load-com)
 
  (setq activedocument (vla-get-activedocument
(vlax-get-acad-object)))
 
 (setq old_cmdecho (getvar
'cmdecho))
 (setvar 'cmdecho 0)

 


  (setq all_lines (ssget '((0 . "LINE")(8 . "MARKS"))))
 
(command "_.pedit" "_m" all_lines "" "_j" 0.0000001 "")
 
 
(ssget "X" '((0 . "LWPOLYLINE")(8 . "MARKS")))
  (setq all_polys
(vla-get-activeselectionset activedocument))
 
  (setvar 'pdmode
34)
  (setvar 'pdsize -1)
 
  (vlax-for poly
all_polys

 

    (setq pt1 (vlax-curve-getPointAtParam poly 0))

 

    (setq pt2
     
(vlax-curve-getPointAtParam poly
       
(/ (vlax-curve-getEndParam poly) 3)
     
)
    )

 

    (setq pt3
     
(vlax-curve-getPointAtParam poly
       
(* (/ (vlax-curve-getEndParam poly) 3) 2)
     
)
    )

 

    (command "_.circle" "_3p" pt1 pt2
pt3)
    (setq circle (vlax-ename->vla-object
(entlast)))
 
   
(vla-addpoint
      (vla-get-modelspace
activedocument)
      (vlax-get-property circle
'center)
    )

 

    (vla-delete circle)
    (vla-delete
poly)
  )

 

  (setvar 'cmdecho old_cmdecho)
 
 
(princ)
)



size=2>;;;=================================================


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
WOW!
Thanks guys! that code is way over my head...I would have never figured it out
on my own. I will get back to you soon and let you know how it works out.
Thanks again!

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

Post to forums  

Autodesk Design & Make Report

”Boost