PDA

View Full Version : Hatch Merge Problem



lcolville
2005-03-03, 03:29 PM
I wrote this program to try and merge two or more hatch areas into one, taking
into account any internal islands.
I thought this should work but it doesn't. Can anyone tell what I'm doing wrong?
Please help!!!


(defun c:hatch_merge ( / )
(prompt "\nSelect a hatch object to add to...")
(setq ss1 (ssget "_:S" '((-4 . "<OR")(0 . "HATCH")(-4 . "OR>"))))
(setq prime_ent (entget (ssname ss1 0)))
(setq loops (cdr (assoc 91 prime_ent)))
(setq seeds (cdr (assoc 98 prime_ent)))
(setq prime_ent (reverse prime_ent))
(repeat seeds
(setq seed_list (cons (assoc 10 prime_ent) seed_list))
(setq prime_ent (cdr prime_ent))
)
(setq prime_ent (reverse prime_ent))
(prompt "\nSelect the hatch objects to be merged...")
(setq ss2 (ssget '((-4 . "<OR")(0 . "HATCH")(-4 . "OR>"))))
(setq lng (sslength ss2))
(setq n 0)
(repeat lng
(setq add_ent (entget (ssname ss2 n)))
(setq loops (cdr (assoc 91 add_ent)))
(setq seeds (cdr (assoc 98 add_ent)))
(setq add_ent (reverse add_ent))
(repeat seeds
(setq seed_list (cons (assoc 10 add_ent) seed_list))
(setq add_ent (cdr add_ent))
)
(setq add_ent (reverse add_ent))
(setq temp_ent add_ent)
(repeat loops
(setq temp_ent (member (assoc 93 (cdr temp_ent)) temp_ent))
(setq temp (cdr (car temp_ent)))
(setq loop_list (cons temp loop_list))
(setq temp_ent (cdr temp_ent))
(repeat temp
(setq point_list (cons (car temp_ent) point_list))
(setq temp_ent (cdr temp_ent))
)
)
(setq n (+ 1 n))
)
(setq seed_list (reverse seed_list))
(setq loop_list (reverse loop_list))
(setq point_list (reverse point_list))
(setq prime_ent (reverse prime_ent))
(setq build_rep (length loop_list))
(repeat build_rep
(setq prime_ent (cons (cons '93 (car loop_list)) prime_ent))
(repeat (car loop_list)
(setq prime_ent (cons (car point_list) prime_ent))
(setq point_list (cdr point_list))
)
(setq loop_list (cdr loop_list))
)
(setq prime_ent (subst (cons '98 (length seed_list)) (assoc 98 prime_ent) prime_ent))
(setq build_rep (length seed_list))
(repeat build_rep
(setq prime_ent (cons (car seed_list) prime_ent))
(setq seed_list (cdr seed_list))
)
(setq prime_ent (reverse prime_ent))
(setq lng (sslength ss2))
(setq n 0)
(repeat lng
(setq del_ent (entget (ssname ss2 n)))
(entdel del_ent)
(setq n (+ 1 n))
)
(entmod prime_ent)
)

lance.81922
2005-03-03, 05:22 PM
Howdy -- I have not yet figured out your program, but I did figure out why the error is happening: you can't ENTDEL an entity list!


(repeat lng
(setq del_ent (entget (ssname ss2 n))) ;;; del_ent is an entity list!!!
(entdel del_ent)
(setq n (+ 1 n))
)

Other than that, it's not obvious to me how the entities are joined into one. I certainly see why the second hatch gets deleted (ENTDEL is like that!)

lcolville
2005-03-03, 08:21 PM
Thanks for the heads up on that bug in my code.
I fixed that part and now it deletes the old hatch objects. (Just like I wanted it to.)
The real problem lies in rebuilding all of the association 10 vertices.
I'm not sure how to index the appropriate location to add the new loops to the
old piece of hatch.

lance.81922
2005-03-03, 09:12 PM
It looks to me like the number of loops is not getting updated in your manipulated entity list, even though the seed list is increasing as you intend. I also think that the 10 entries for the seeds aren't laid out correctly right after the 98 group (number of seeds). Stay after it.....

cwitt
2005-03-03, 09:14 PM
just curious... what version of CAD are you using?

lcolville
2005-03-03, 09:46 PM
I am using AutoCAD 2005.