TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: polhub on November 01, 2017, 01:47:02 pm

Title: Move Block Grips as a Group
Post by: polhub on November 01, 2017, 01:47:02 pm
We have a set of dynamic blocks, each block has two points (grips); one input, one output. We use many of these blocks in our drawing packages and it becomes cumbersome to click on each block, then shift click on the grip we want to move.

I am looking for a method that will be more similar to the move command where I draw a crossing window (or fence) and can move a group of either input grips or output grips. I have done some research and, from what I can find, this may not be possible, but of course unless I hit the exact terms in Google things like this are always hard to find. Does anyone have experience with a situation like this, is it possible?

Thanks
Title: Re: Move Block Grips as a Group
Post by: polhub on November 14, 2017, 11:47:28 am
81 views and no responses, don't know if that is good or bad.

I found this but it applies to the attributes not specifically to a grip.

https://www.theswamp.org/index.php?topic=19881.0 (https://www.theswamp.org/index.php?topic=19881.0)
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 14, 2017, 11:50:05 am
Can you post an example of this block you're trying to move? I'm not quite understanding your intentions.
Title: Re: Move Block Grips as a Group
Post by: polhub on November 14, 2017, 01:34:33 pm
If you look at the attached I have included four of the same block in question. If i wanted to move only the four diamond shapes on the right (and their associated attributes) and leave the ones on the left where they are I need to window them then shift click each one individually to move them. I am looking for a simpler process, we can have hundreds of these in a drawing usually in groups of 4 to 10 that we need to move on a regular basis and all the clicking is tedious.

This is one block to allow us to fill in other text via fields so separating the ends to make two blocks isn't really an option.
Title: Re: Move Block Grips as a Group
Post by: Crookedmonk on November 14, 2017, 03:39:47 pm
Are you looking to move the position 2 coordinates to a know location, or to locate to a "random" location?
Title: Re: Move Block Grips as a Group
Post by: polhub on November 15, 2017, 07:21:21 am
It is a random location. Ultimately we would like to be able to window a group of either position 1 or position 2 and move them like the standard move command.
Title: Re: Move Block Grips as a Group
Post by: Crookedmonk on November 15, 2017, 09:06:59 am
Pol, is this what you are looking for?
http://www.cadtutor.net/forum/archive/index.php/t-14580.html
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 15, 2017, 10:25:23 am
Give this a try:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:foo (/ a b bp c l mp p p1 p2 s x x1 x2 y y1 y2 _x _y)
  3.  ;; RJP - 11.15.2017
  4.  (if (and (setq p1 (getpoint "\nSpecify first corner: "))
  5.   (setq p2 (getcorner p1 "\nSpecify opposite corner:"))
  6.   (setq l (list p1 p2))
  7.   (setq l (list (apply 'mapcar (cons 'min l)) (apply 'mapcar (cons 'max l))))
  8.   (setq s (ssget "_C" p1 p2 '((0 . "insert") (2 . "`*U*,SL-WIRE-FLAG"))))
  9.   (setq p
  10.  (mapcar
  11.    '(lambda (x)
  12.       (if (setq p1 (vl-remove-if-not
  13.      '(lambda (c) (wcmatch (strcase (vla-get-propertyname c)) "POSITION*"))
  14.      (vlax-invoke x 'getdynamicblockproperties)
  15.    )
  16.   )
  17. '(lambda (a b) (< (vla-get-propertyname a) (vla-get-propertyname b)))
  18.       )
  19.       (vlax-get x 'insertionpoint)
  20. )
  21.       )
  22.     )
  23.    (vl-remove-if-not
  24.      '(lambda (d) (vlax-write-enabled-p d))
  25.      (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  26.    )
  27.  )
  28.   )
  29.   (setq bp (getpoint "\nSpecify base point: "))
  30.   (setq mp (getpoint bp "\nSpecify second point: "))
  31.      )
  32.    (foreach x (vl-remove 'nil p)
  33.      (mapcar 'set '(x1 y1 x2 y2) (mapcar '(lambda (y) (vlax-get y 'value)) (setq c (car x))))
  34.      (setq _x (car (cadr x)))
  35.      (setq _y (cadr (cadr x)))
  36.      (if (setq a (cond ((and (<= (car (mapcar 'car l)) (+ _x x1) (cadr (mapcar 'car l)))
  37.      (<= (car (mapcar 'cadr l)) (+ _y y1) (cadr (mapcar 'cadr l)))
  38. )
  39. (list (car c) (cadr c) (list x1 y1))
  40. )
  41. ((and (<= (car (mapcar 'car l)) (+ _x x2) (cadr (mapcar 'car l)))
  42.      (<= (car (mapcar 'cadr l)) (+ _y y2) (cadr (mapcar 'cadr l)))
  43. )
  44. (list (caddr c) (cadddr c) (list x2 y2))
  45. )
  46.  )
  47.  )
  48. (progn (setq b (polar (last a) (angle bp mp) (distance bp mp)))
  49.       (vlax-put (car a) 'value (car b))
  50.       (vlax-put (cadr a) 'value (cadr b))
  51. )
  52.      )
  53.    )
  54.  )
  55.  (princ))
Title: Re: Move Block Grips as a Group
Post by: polhub on November 15, 2017, 11:34:03 am
ronjonp,

Nice!

I am a bit confused though, it works in the drawing I sent you but I can't make it work in any other drawing. Can you think of why that would be? I copied the block (from the drawing I sent you) to a new drawing and it no longer works, very strange.
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 15, 2017, 11:54:52 am
I just realized that the x y point values are relative to the block insertion point  :oops: . Gimme a bit and I'll try to fix :)

*Code fixed above .. give it a try!
Title: Re: Move Block Grips as a Group
Post by: polhub on November 15, 2017, 01:51:18 pm
Works like a charm!! Never thought that could be done!

Now, do I just change the block name in line 7 if I have other blocks that work the same or can I add a comma and list the others?

Can you clarify the use of the `*u*, I am unfamiliar with that?

Thanks, this should save some time. BIG thumbs up to you (no thumbs up imogee available)
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 15, 2017, 02:17:00 pm
Works like a charm!! Never thought that could be done!

Now, do I just change the block name in line 7 if I have other blocks that work the same or can I add a comma and list the others?

Can you clarify the use of the `*u*, I am unfamiliar with that?

Thanks, this should save some time. BIG thumbs up to you (no thumbs up imogee available)
Glad to help out :)
As far as the block filter goes, you should be able to add your names to it "`*U*,SL-WIRE-FLAG,block1,block2..." and the code should work if they have the same point parameters. The`*U* filter catches any dynamic blocks that have been modified since their DXF 2 code changes.
Title: Re: Move Block Grips as a Group
Post by: polhub on November 15, 2017, 04:04:57 pm
I thought as much and added four other blocks no luck only the attributes move not the line work and only one side moves. These have attributes like the block above but also employ visibility states and lookup tables. I am not sure if that has anything to do with it or not.

Thanks again for the help you have provided thus far.
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 15, 2017, 04:11:04 pm
I'd have to filter out only point parameters ... that's why it's not working. Are they all named "Position*"?
Title: Re: Move Block Grips as a Group
Post by: polhub on November 16, 2017, 07:44:36 am
Yes, on the left side there is Position 1 (the one we want) and Position 3, on the right side it is Position 2 (the one we want) and Position 4. Positions 2 and 4 move a bit of text relative to Positions 1 and 2 respectively, I hope that makes sense.

Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 16, 2017, 08:58:54 am
Yes, on the left side there is Position 1 (the one we want) and Position 3, on the right side it is Position 2 (the one we want) and Position 4. Positions 2 and 4 move a bit of text relative to Positions 1 and 2 respectively, I hope that makes sense.
The 'grip' selection is based on the window used. I updated the code above to exclude dynamic properties not named "POSITION*" .. see if that works for you.
Title: Re: Move Block Grips as a Group
Post by: polhub on November 16, 2017, 01:32:01 pm
All works great!

Isolated all the DBlock parameters so only position 1 & 2 were used, everything else I made more descriptive (as I should have done in the first place).

Thanks for the help, learned a lot from this one.
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 16, 2017, 01:43:35 pm
Glad you learned something  8)
Title: Re: Move Block Grips as a Group
Post by: cgeorg13 on November 17, 2017, 07:07:38 am
That is some great usage of lambda and mapcar, ronjonp!

I'm not too familiar with its functionality since I rarely use it but stepping through your code line by line helped me understand it a bit more, thanks!
Title: Re: Move Block Grips as a Group
Post by: ronjonp on November 17, 2017, 10:07:51 am
That is some great usage of lambda and mapcar, ronjonp!

I'm not too familiar with its functionality since I rarely use it but stepping through your code line by line helped me understand it a bit more, thanks!
Glad you could learn something from it!  :)