Jump to content
Luís Augusto

Select associated objects a field autocad

Recommended Posts

Luís Augusto

Hi guys, is there any command that performs the selection of objects associated with an object field?

I'm using an excellent routine performed by Lee Mac to make the sum of texts. At the end of addition, it generates a field.

In some moments I need to check the path where I spent. It would be very interesting if we could make a quick selection using the ID of the objects contained in the field.

I should point out that I still have no experience with the Lisp language.

Thank in advance.

Luis Augusto.

 

Currently with autocad 2010

Translated by google

Share this post


Link to post
Share on other sites
BlackBox

You'll need to first parse the FieldCode string, and then iterate the appropriate Block Object given the ObjectId extracted.

Edited by BlackBox

Share this post


Link to post
Share on other sites
Tharwat

My try ...

 

(defun c:Test (/ ss i sn fd cd l s sad j e p n)
;;;        --=={ Tharwat 07. 07. 2013 }==--    ;;;
;;; Function to select the related Texts to a field     ;;;
 (if (progn
       (princ "\n Select field Text :")
       (setq ss (ssget "_+.:S" '((0 . "MTEXT"))))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (setq fd (vla-fieldcode (vlax-ename->vla-object sn)))
       (while
         (setq cd (vl-string-search "%<\\_ObjId " fd))
          (setq l  (cons (atoi (substr fd (+ cd 11) 10)) l)
                fd (substr fd (+ cd 11))
          )
       )
     )
   )
 )

 (if
   (and l
        (setq
          s (ssget "_X"
                   (list '(0 . "TEXT,MTEXT") (cons 410 (getvar 'ctab)))
            )
        )
   )
    (progn
      (setq sad (ssadd))
      (repeat (setq j (sslength s))
        (setq e (ssname s (setq j (1- j))))
        (if (member (vla-get-ObjectID (vlax-ename->vla-object e)) l)
          (ssadd e sad)
        )
      )
    )
 )
 (if (and sad (> (sslength sad) 0))
   (progn
     (setq p (cdr (assoc 10 (entget (ssname ss 0)))))
     (repeat (setq n (sslength sad))
       (grdraw p
               (cdr (assoc 10 (entget (ssname sad (setq n (1- n))))))
               2
               1
       )
     )
   )
 )
 (princ)
)
(vl-load-com)


Share this post


Link to post
Share on other sites
Luís Augusto
You'll need to first parse the FieldCode string, and then iterate the appropriate Block Object given the handle (ObjectId) extracted.

 

Dear BlackBox, thanks for the reply. Unfortunately still can not create my own codes. Hopefully soon get.

 

See this old program:

 

http://www.theswamp.org/index.php?topic=39951

 

[ membership may be required ]

 

Lee, thanks for helping me again. Unfortunately I still have no access to www.theswamp.org. I sent an email to Mark to get access.

 

My try ...

 

(defun c:Test (/ ss i sn fd cd l s sad j e p n)
;;;        --=={ Tharwat 07. 07. 2013 }==--    ;;;
;;; Function to select the related Texts to a field     ;;;
 (if (progn
       (princ "\n Select field Text :")
       (setq ss (ssget "_+.:S" '((0 . "MTEXT"))))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (setq fd (vla-fieldcode (vlax-ename->vla-object sn)))
       (while
         (setq cd (vl-string-search "%<\\_ObjId " fd))
          (setq l  (cons (atoi (substr fd (+ cd 11) 10)) l)
                fd (substr fd (+ cd 11))
          )
       )
     )
   )
 )

 (if
   (and l
        (setq
          s (ssget "_X"
                   (list '(0 . "TEXT,MTEXT") (cons 410 (getvar 'ctab)))
            )
        )
   )
    (progn
      (setq sad (ssadd))
      (repeat (setq j (sslength s))
        (setq e (ssname s (setq j (1- j))))
        (if (member (vla-get-ObjectID (vlax-ename->vla-object e)) l)
          (ssadd e sad)
        )
      )
    )
 )
 (if (and sad (> (sslength sad) 0))
   (progn
     (setq p (cdr (assoc 10 (entget (ssname ss 0)))))
     (repeat (setq n (sslength sad))
       (grdraw p
               (cdr (assoc 10 (entget (ssname sad (setq n (1- n))))))
               2
               1
       )
     )
   )
 )
 (princ)
)
(vl-load-com)


 

Tharwat, thanks for your reply.

Unfortunately, the program did not work on my machine here, also did not return error.

I am attaching the design to perform a test.

I appreciate everyone's attention.

 

SUM.dwg

 

Luis Augusto.

Translated by google

Share this post


Link to post
Share on other sites
Luís Augusto
See this old program:

 

http://www.theswamp.org/index.php?topic=39951

 

[ membership may be required ]

 

Beautiful job Lee.:celebrate:

Congratulations. Not even in a dream could imagine something so perfect for my situation.

This routine is fantastic, I run the commands zoom and pan, temporary lines keeps the same way.

Surely the program will greatly improve my work.

I can post the code for others with the same need to see the solution?

 

Thank you all.

 

Best regards,

Luís Augusto.

 

Translated by google

Edited by Luís Augusto

Share this post


Link to post
Share on other sites
Tharwat

 

Tharwat, thanks for your reply.

Unfortunately, the program did not work on my machine here, also did not return error.

I am attaching the design to perform a test.

I appreciate everyone's attention.

 

Luis Augusto.

Translated by google

 

That's odd , I tried the code on Cad 2010 and 2013 and it works well .

 

The routine ask you to pick on field string then it will draw a vector line to the related text entities to that field .

 

Are you using my code separately or you are adding them to another codes ?

Share this post


Link to post
Share on other sites
Lee Mac
Beautiful job Lee.:celebrate:

Congratulations. Not even in a dream could imagine something so perfect for my situation.

This routine is fantastic, I run the commands zoom and pan, temporary lines keeps the same way.

Surely the program will greatly improve my work.

 

That's fantastic to hear, thank you for your kind compliments Luís!

I'm delighted that the program will be useful in your work.

 

I can post the code for others with the same need to see the solution?

 

I have now attached the program to this post for those without access to the Swamp.

 

FieldObjects.gif

FieldObjects.lsp

Share this post


Link to post
Share on other sites
Luís Augusto
That's odd , I tried the code on Cad 2010 and 2013 and it works well .

 

The routine ask you to pick on field string then it will draw a vector line to the related text entities to that field .

 

Are you using my code separately or you are adding them to another codes ?

 

Tharwat, I do not dare to change codes. I am trying to understand so many parentheses. :unsure:

Tomorrow i will test your routine on other machines and give you feedback.

I believe that the forum users here could do the same, thus we would have two solutions.

Thanks for disposal.

 

Best Regards, Luis Augusto.

 

Translated by google

Share this post


Link to post
Share on other sites
Tharwat

Tomorrow i will test your routine on other machines and give you feedback.

 

I will be waiting for that test :thumbsup:

 

Thank you .

Share this post


Link to post
Share on other sites
BlackBox

That's pretty schnazzy, Lee :beer:

Share this post


Link to post
Share on other sites
Lee Mac
That's pretty schnazzy, Lee :beer:

 

Cheers BB :thumbsup:

Share this post


Link to post
Share on other sites
Luís Augusto
I will be waiting for that test :thumbsup:

 

Thank you .

 

How will you Tharwat?

As promised, I tested the program on three machines. Two OS with 32bits and 64bits another.

There is a limitation in 64bit OS. With 32bit OS works very well. I really liked the fact that you can select other fields and keep the old temporary line.

Another observation is how to zoom and pan commands eliminate these temporary lines, the lines would be desirable to remain until press any key.

You can make these improvements?

 

Thank you for sharing your work with us.

Big hug.

 

Luis Augusto.

 

Translated by google

Share this post


Link to post
Share on other sites
Tharwat

As promised, I tested the program on three machines. Two OS with 32bits and 64bits another.

There is a limitation in 64bit OS. With 32bit OS works very well. I really liked the fact that you can select other fields and keep the old temporary line.

Another observation is how to zoom and pan commands eliminate these temporary lines, the lines would be desirable to remain until press any key.

You can make these improvements?

 

Thank you for sharing your work with us.

 

 

Thanks for keeping the promise and please try this modified code and let me know .

 

(defun c:Test (/ *error* ss i sn fd cd l s sad j e p n lst)
;;;       ---===={ Tharwat 07. 07. 2013 }====---    ;;;
;;; Function to select the related Texts to a field     ;;;
 (defun *error* (x) (redraw) (princ "\n*Cancel*"))
 (if (progn
       (princ "\n Select field Text :")
       (setq ss (ssget "_+.:S" '((0 . "MTEXT"))))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if (setq fd (vla-fieldcode (vlax-ename->vla-object sn)))
       (while
         (setq cd (vl-string-search "%<\\_ObjId " fd))
          (setq l  (cons (atoi (substr fd (+ cd 11) 10)) l)
                fd (substr fd (+ cd 11))
          )
       )
     )
   )
 )

 (if
   (and l
        (setq
          s (ssget "_X"
                   (list '(0 . "TEXT,MTEXT") (cons 410 (getvar 'ctab)))
            )
        )
   )
    (progn
      (setq sad (ssadd))
      (repeat (setq j (sslength s))
        (setq e (ssname s (setq j (1- j))))
        (if (member (vla-get-ObjectID (vlax-ename->vla-object e)) l)
          (ssadd e sad)
        )
      )
    )
 )
 (if (and sad (> (sslength sad) 0))
   (progn
     (setq p (cdr (assoc 10 (entget (ssname ss 0)))))
     (repeat (setq n (sslength sad))
       (setq
         lst (cons
               (cdr (assoc 10 (entget (ssname sad (setq n (1- n))))))
               lst
             )
       )
     )
     (while (eq (car (grread t 15 0)) 5)
       (princ "\r Press any key to exit :")
       (foreach x lst
         (grdraw p x 2 1)
       )
     )
     (redraw)
   )
 )
 (princ)
)
(vl-load-com)

Share this post


Link to post
Share on other sites
Luís Augusto
That's fantastic to hear, thank you for your kind compliments Luís!

I'm delighted that the program will be useful in your work.

 

 

 

I have now attached the program to this post for those without access to the Swamp.

 

[ATTACH]42816[/ATTACH]

 

 

Hello Lee

Do not want to seem abused, but I was very curious.

I am using this routine to check the way I did when I add the length of a cable layout for an electric whip.

Our colleague fixo is helping me with a routine to facilitate the completion of the table From / To. The program will generate a calculated field within the table.

When accessing a FIELD within the table, it is a bit strange the line from the origin, so I had the following idea.

 

It would be possible to change the program so that the selection of the FIELD, the source was not the text but a block with the name "NewOrigin" in the center of the layout? :idea:

 

Luis Augusto.

 

Translated by Gloogle

Share this post


Link to post
Share on other sites
Lee Mac
When accessing a FIELD within the table, it is a bit strange the line from the origin...

 

Hi Luís,

 

I hadn't tested the program with fields located within table cells, but will look to resolve this issue when I get some spare time to work on the program.

 

Lee

Share this post


Link to post
Share on other sites
Luís Augusto
Hi Luís,

 

I hadn't tested the program with fields located within table cells, but will look to resolve this issue when I get some spare time to work on the program.

 

Lee

 

Hi Lee,

I think I did not express myself well.

I believe that in my case, a block as the source, would be an excellent solution for the type of work I do. In certain situations, my list of cables may be too far from the layout of the electrical harness.

I plan to deploy your code after the sum of the cables. At this time, IDobjects must be in program memory yet. Thus the existing function would direct origin of the lines to the block NewOrigin. That way I can make the conference the way immediately.

Sorry for the misunderstanding. :oops:

 

Regards, Luis Augusto.

 

Translated by gloogle

Share this post


Link to post
Share on other sites
Luís Augusto
Thanks for keeping the promise and please try this modified code and let me know .

 

 

Hello Tharwat.

Sorry for the delay, I not had the opportunity to test before. :(

I installed VirtualBox on my machine. Now I can test code for 32bit OS.....;)

That's it, your code works perfectly, however, with the last review, he missed an interesting feature, which was to select multiple objectFIELDS. No problem.

Congratulations my friend, I hope to one day be able to write my own code too.:thumbsup:

 

Best regards, Luís Augusto.

Share this post


Link to post
Share on other sites
Tharwat

That's it, your code works perfectly, however, with the last review, he missed an interesting feature, which was to select multiple objectFIELDS. No problem.

Congratulations my friend, I hope to one day be able to write my own code too.:thumbsup:

 

Best regards, Luís Augusto.

 

Thank you for your test and for following your promises with it , it is much appreciated . :thumbsup:

 

Don't worry , you'd write your own codes if you insist on learning and working on programming daily , and I wish you best of luck .

 

Tharwat

Share this post


Link to post
Share on other sites
pBe
See this old program:...

 

Excellent idea Lee. Me like it muchísimo. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×