• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Contributor
    Posts: 21
    Registered: ‎10-30-2012
    Accepted Solution

    Add attribute to selected blocks (XY coordinates)

    424 Views, 13 Replies
    11-30-2012 11:02 PM

    i have found the following lisp in a previous thread: (shows XY coordinates of the selected blocks)

     

     (defun C:MyFunc (/ ss Index Ename Lst)
      (while (or (not ss) (= 0 (sslength ss))) (setq ss (ssget '((0 .
    "INSERT")))))
      (if ss
        (progn
          (setq Index 0)
          (repeat (sslength ss)
    (setq Ename (ssname ss Index)
          Lst (append (list (cdr (assoc 10 (entget Ename)))) Lst)
          Index (1+ Index)
          )
    )
          (foreach item Lst (terpri) (princ item))
          )
        )
      (princ)
      )

     

    i want this information to be added to the blocks as hidden attributes so that i can extract them by attout.

    is it possible?

     

     

    any other suggestions would be greatly appreciated. the work to be done is : attout to excel, autofill an attribute (numbering) then attin.

     

    but my problem is that i cant think of a way to number those blocks IN ORDER (ie top to bottom or left to right) unless by sorting them in excel first by their x or y coordinates

     

     

     

     

     

    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: Add attribute to selected blocks (XY coordinates)

    11-30-2012 11:16 PM in reply to: vahe.holtian

    vahe.holtian wrote:

     

    .....i want this information to be added to the blocks as hidden attributes so that i can extract them by attout.

    is it possible?

     

    any other suggestions would be greatly appreciated. the work to be done is : attout to excel, autofill an attribute (numbering) then attin.

     

    but my problem is that i cant think of a way to number those blocks IN ORDER (ie top to bottom or left to right) unless by sorting them in excel first by their x or y coordinates

         


    Are you wanting to select from a list of blocks or ALL? 

    Do you have an existing  block with invisible attributes?

     

    To sort the blocks look into this link BlockSSSort.lsp by Kent Cooper <-- post # 9 [kudos to Kent]

     

     

     

     

     

    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎10-30-2012

    Re: Add attribute to selected blocks (XY coordinates)

    12-01-2012 05:01 AM in reply to: pbejse

    after reading the suggested page for hours im completely lost.

     

    it seems to be what i need but i cant figure out the rest. what is blockSSSort.lsp doing?

     

     

     

     

    i want to select many blocks and increment the value of 1 of its attributes but the increment should have a prefix and a 4 4 digit format so i thought just adding the X coordinates as hidden attributes (to be created) and doing the job in excel would be easier

     

     

    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: Add attribute to selected blocks (XY coordinates)

    12-01-2012 09:36 PM in reply to: vahe.holtian

    vahe.holtian wrote:

     

    it seems to be what i need but i cant figure out the rest. what is blockSSSort.lsp doing?

     


     

    ...... but my problem is that i cant think of a way to number those blocks IN ORDER (ie top to bottom or left to right) unless by sorting them in excel first by their x or y coordinates....

     

     

    BlockSSSort.lsp will sort the blocks in order so that you can number the blocks Top to Bottom or Left to Right

     


    vahe.holtian wrote:

     

     i want to select many blocks and increment the value of 1 of its attributes but the increment should have a prefix and a 4 4 digit format so i thought just adding the X coordinates as hidden attributes (to be created) and doing the job in excel would be easier

     

     


    You mean create a block with invisible attributes on the existing blocks to contain the X and Y coordinates for tthe sole purpose of sorting the blocks?

    Hence the function BlockSSSort.lsp so you can make do without  creating the invisible attributes. 

     

    But then again you would be using DATA EXTRACTION. I beleive you can sort the output via dialog box

     

    dialog.JPG

     

    Knowing that now, do you still need to add the invisible attribute and  number the blocks ?

    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎10-30-2012

    Re: Add attribute to selected blocks (XY coordinates)

    12-02-2012 02:29 PM in reply to: vahe.holtian
    I wanted to create a new hidden attribute value containing the x coordinate of the block. Anyway, there seems to be smarter ways to do it.

    What is BlockSSSort.lsp doing? Im trying (BSSS "t" "l") but what is the result?

    (also, dataextraction is not convienient to me because I need to change those values based on an increment system ie A098, A145, A832, B134, B009 should become A001,A002,A003,B001,B002 based on their position)

    Please can you guide me a bit further regarding the BlockSSSort.lsp?

    Thank you for ur assistance!


    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎10-30-2012

    Re: Add attribute to selected blocks (XY coordinates)

    12-02-2012 02:31 PM in reply to: vahe.holtian
    Is it possible to run the attin command on a dataextraction output file? That way I can simply add the x coordinate, edit in excel and update the new values
    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,058
    Registered: ‎09-13-2004

    Re: Add attribute to selected blocks (XY coordinates)

    12-03-2012 08:29 AM in reply to: vahe.holtian

    vahe.holtian wrote:
    I wanted to create a new hidden attribute value containing the x coordinate of the block. ....

    What is BlockSSSort.lsp doing? Im trying (BSSS "t" "l") but what is the result?
    ....

    That routine simply sorts selected Blocks in positional order, in the positional directions that the User specifies in the arguments to the function, and returns a list of Block-insertion entity names in that sorted order, as well as saving that list into a variable.  It doesn't do anything like add an Attribute to the Blocks, but I suppose it could be used as a starting point to do so, if you want something about that Attribute to be incremented in positional order.  If you need an Attribute only to indicate the X or X & Y coordinate(s), that doesn't sound like any kind of positional sorting would be required.  But if the only reason for the Attribute is to feed information out to something that will sort, this can spare you that middle-man.  If all you need to sort by is X coordinate as quoted above, rather by X and Y coordinate as in some earlier messages, that could be done a lot more simply than with BlockSSSort.lsp -- a much simplified version of it would do.

     

    Also, are these Blocks that already have an Attribute for whatever you want to put in it, and it's only a matter of getting the value into it?  Or will an Attribute need to be added to the Block definition(s)?  Are they always going to be insertions of the same Block, or different Blocks?

     

    I think a before-and-after sample drawing, or a sample drawing and a sample file of whatever the ultimate output would be, would clarify what you're trying to do.

     

    EDIT:  Looking back, I noticed one line I hadn't caught before:

    "...i want to select many blocks and increment the value of 1 of its attributes but the increment should have a prefix and a 4 4 digit format...."

    If that prefix is the sort order integer, and the 4 4 digit format are the X and Y coordinates, and the Attribute already exists, that sounds reasonably doable with BSSS as a start.  Is that what you're after?

    Kent Cooper
    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎10-30-2012

    Re: Add attribute to selected blocks (XY coordinates)

    12-04-2012 09:06 AM in reply to: Kent1Cooper

    i uploaded a sample drawing.

     

    the whole point is getting those values (A001,A002,A003,B001,B002,S001....) numbered correctly and in the same format and in a way that when a person takes the drawing he can follow some path to read through all of them in a neat way, just not scrambled.

     

    many thanks to you!

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,058
    Registered: ‎09-13-2004

    Re: Add attribute to selected blocks (XY coordinates)

    12-04-2012 10:05 AM in reply to: vahe.holtian

    vahe.holtian wrote:

    .... 

    the whole point is getting those values (A001,A002,A003,B001,B002,S001....) numbered correctly and in the same format and in a way that when a person takes the drawing he can follow some path to read through all of them in a neat way, just not scrambled.

    ....


    It appears that all Blocks with BAR_MARK Attribute values beginning with A are of the same Block name, and all those beginning with B are of the same other block name, but those beginning with S are of various Block names.  So it looks like a routine wouldn't be able to just positionally sort all the insertions each Block name separately, because you'd end up with [for example] more than one S001.  But if those values already exist in their scrambled order and with initial letters that are to remain, a routine could certainly be made to read the first letter of that Attribute value, put each Block into a list of those that share that first letter, positionally sort each of those lists [apparently, in this example, using the "L" and "T" options in BSSS -- would you always want them sorted in the same way?], and replace the numerical portion of that Attribute value in each Block of each list with a positionally-sequential number.  It wouldn't require exporting anything or doing the sorting in an external program.  Does that sound like what you're after?

    Kent Cooper
    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: Add attribute to selected blocks (XY coordinates)

    12-04-2012 11:35 PM in reply to: vahe.holtian

    vahe.holtian wrote:

    i uploaded a sample drawing.

     

    the whole point is getting those values (A001,A002,A003,B001,B002,S001....) numbered correctly and in the same format and in a way that when a person takes the drawing he can follow some path to read through all of them in a neat way, just not scrambled.

     

    many thanks to you!


    Same queries as Kents vahe.holtian, I think its doable,

     

    Why did you end up with those block names anyway? 

     

     

    Please use plain text.