Author Topic: Prevent/move multiple block insertion on same point  (Read 1419 times)

0 Members and 1 Guest are viewing this topic.

ifncdylan

  • Guest
Prevent/move multiple block insertion on same point
« on: January 29, 2018, 09:42:16 PM »
Hey all, long time no see. I've run into a bit of a snag when creating a routine.

I have a bunch of points with xdata which are iterated through and a block inserted to match the xdata on the point. If there are multiple points on the same insertion point with the same block being inserted, the script inserts blocks all in the same spot, sometimes this could be 20 or 30 blocks which then need to be manually moved in order to be able to read the attributes.

I wrote a routine which checks for existing matching blocks at a given insertion point and offsets the point (given an offset distance) until the point no longer matches blocks:

Code - Auto/Visual Lisp: [Select]
  1. (defun blockInspt ( name base right up / )
  2.   (while
  3.     (setq existing (ssget "_X" (list (cons 2 name) (cons 10 base))))
  4.         (setq base (shiftup (shiftright base right) up))
  5.   )
  6.   base
  7. )
  8.  
  9. ;; aliases for shifting an insertion point left/right/up/down (crude)
  10. (defun shiftright ( pt dist / p1 p2 p3 ) (list (+ (car pt) dist) (cadr pt) 0.0))
  11. (defun shiftup ( pt dist / p1 p2 p3 ) (list (car pt) (+ (cadr pt) dist) 0.0))
  12.  
  13.  

This works fine, but it takes FOREVER (looks like the ssget selection filter takes 1-2 secs and in some drawings we have 10000 of these points to go through).

Is there any better way to do this "Check insertion point for matching blocks and offset until blank space is found"?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Prevent/move multiple block insertion on same point
« Reply #1 on: January 30, 2018, 03:58:22 AM »
Can't you fix your 'insert blocks' code so that you avoid this problem?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Prevent/move multiple block insertion on same point
« Reply #2 on: January 30, 2018, 08:01:46 AM »
I would personally approach the problem in the following way:
  • In the block insertion program, first retrieve a list of the insertion points for all existing blocks in the drawing.
  • When inserting a new block, check insertion point coordinates against the existing list.
  • If the insertion point already exists in the list:
    • Add an offset in a given direction and test the offset point against the list.
    • If the offset point is also found, offset the original point in another direction and test again.
    • Continue until either the point is no longer found in the list, or until all four offset directions have been tested.
    • If the point is still found, double the offset distance and repeat with all four directions.
    • Finally, add the block insertion point to the list.
  • If not found in the list:
    • Simply insert the block and add the new insertion point to the list.
« Last Edit: January 30, 2018, 08:05:49 AM by Lee Mac »