TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Marc'Antonio Alessi on October 11, 2018, 04:41:51 PM

Title: Best method to associate two objects
Post by: Marc'Antonio Alessi on October 11, 2018, 04:41:51 PM
Best method to associate two objects that is simple and visible in some way, which includes the possibility of copying objects, stretch or editing the object linked to the label, reassociate...
The objective is to (for example) select all the labels (ssget ...) and one by one find the object connected to it.
Xdata? Groups? ...
Title: Re: Best method to associate two objects
Post by: ribarm on October 12, 2018, 01:40:01 AM
Connection line should be in specific layer so you don't mess it with other lines for other purposes... Then iterate through all connection lines and acquire end points entities and create association list : ((block-ename1 entity-ename1) (block-ename2 entity-ename2)...)... Then just iterate through list and find point-lower-left and point-upper-right - you have to use (vla-getboundingbox) on both entities - to get ll and ur - something like this (setq ll (apply 'mapcar (cons 'min (list p1ll p1ur p2ll p2ur)))) and (setq ur (apply 'mapcar (cons 'max (list p1ll p1ur p2ll p2ur))))... Then before next iteration loop (vl-cmdf "_.ZOOM" "_W" "_non" ll "_non" ur) and pause (vl-catch-all-apply 'grread (list nil))... Process iteration until you find desired link - hit ESC to terminate routine...
Title: Re: Best method to associate two objects
Post by: Marc'Antonio Alessi on October 12, 2018, 03:35:20 AM
Thanks Marko, this is the method that I am, more or less, using now. I'm looking for something safer to avoid mistakes but at the same time do not obliterate the user to procedures complicated and difficult  to keep under control.
Title: Re: Best method to associate two objects
Post by: Grrr1337 on October 12, 2018, 04:46:20 AM
Maybe an assoc or matrix list that contains the handles?  And the list will be a global variable or stored into some dictionary?
Title: Re: Best method to associate two objects
Post by: Marc'Antonio Alessi on October 12, 2018, 05:16:29 AM
Maybe an assoc or matrix list that contains the handles?  And the list will be a global variable or stored into some dictionary?
I thought of connecting the two objects (block and polyline) writing on both a cross 1005 xdata with the respective handles...
Title: Re: Best method to associate two objects
Post by: ronjonp on October 12, 2018, 08:46:09 AM
Any specific reason you're not using mleaders?
Title: Re: Best method to associate two objects
Post by: Marc'Antonio Alessi on October 12, 2018, 04:38:55 PM

Any specific reason you're not using mleaders?
I use mleader in a similar context but where the end of the leader is always on the connected object
(in that case a block). So, working in reverse, starting from each block I find the leader "associated" with:
; _Utils_SsgetMLeader '(1905.13 2043.22 0.0) 1)
(defun _Utils_SsgetMLeader (PntLst FuzFac)
  (ssget "_X"
    (list
      '(0 . "MULTILEADER")
      '(-4 . ">=,>=,>=")
       (cons 15 (mapcar '- PntLst (list FuzFac FuzFac 0)))
      '(-4 . "<=,<=,<=")
       (cons 15 (mapcar '+ PntLst (list FuzFac FuzFac 0)))
    )
  )
)