Author Topic: ssget filter hyperlink  (Read 414 times)

0 Members and 1 Guest are viewing this topic.

NameWaster

  • Mosquito
  • Posts: 10
ssget filter hyperlink
« on: August 26, 2022, 08:49:54 AM »
Hello,
LISP noob here.

I want to make a selection set of MPOLYGON entities which have a specific Hyperlink value.
I am using:
(ssget "_X" '((0 . "MPOLYGON") (1000 . "Test-EG-001")))

This does not work.
I know Hyperlink is extended data and that I read that it needs a "-3" but I don't understand where exactly.

Any help would be greatly appreciated!

ronjonp

  • Needs a day job
  • Posts: 7446
Re: ssget filter hyperlink
« Reply #1 on: August 26, 2022, 10:25:35 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" '((0 . "MPOLYGON") (-3 ("PE_URL" (1000 . "Test-EG-001")))))

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12711
  • London, England
Re: ssget filter hyperlink
« Reply #2 on: August 26, 2022, 03:19:56 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" '((0 . "MPOLYGON") (-3 ("PE_URL" (1000 . "Test-EG-001")))))

AFAIK, you can't filter below the xdata application ID within an ssget filter list, but I could be wrong.

EDIT - confirmed:
http://docs.autodesk.com/ACD/2011/ENU/filesALG/WS73099cc142f4875516d84be10ebc87a53f-7a2e.htm

Lee Mac

  • Seagull
  • Posts: 12711
  • London, England
Re: ssget filter hyperlink
« Reply #3 on: August 26, 2022, 03:28:48 PM »
Perhaps something like this -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / e i s )
  2.     (if (setq s (ssget "_X" '((0 . "MPOLYGON") (-3 ("PE_URL")))))
  3.         (repeat (setq i (sslength s))
  4.             (setq i (1- i)
  5.                   e (ssname s i)
  6.             )
  7.             (or (member '(1000 . "Test-EG-001") (cdadr (assoc -3 (entget e '("PE_URL")))))
  8.                 (ssdel e s)
  9.             )
  10.         )
  11.     )
  12.     (sssetfirst nil s)
  13.     (princ)
  14. )

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #4 on: September 13, 2022, 10:30:23 AM »
Perhaps something like this -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / e i s )
  2.     (if (setq s (ssget "_X" '((0 . "MPOLYGON") (-3 ("PE_URL")))))
  3.         (repeat (setq i (sslength s))
  4.             (setq i (1- i)
  5.                   e (ssname s i)
  6.             )
  7.             (or (member '(1000 . "Test-EG-001") (cdadr (assoc -3 (entget e '("PE_URL")))))
  8.                 (ssdel e s)
  9.             )
  10.         )
  11.     )
  12.     (sssetfirst nil s)
  13.     (princ)
  14. )

Hello!
Late reply, I know. First of all, thanks for the help so far!

Now all I would need is the following:

After the sssetfirst from your suggested code, is there a way I can now get to the entityname (ename) of that entity which sssetfirst selects for me?
You see, I really just need the ename of that one MPolygon entity that has the specific Hyperlink value.

I know I should be able to figure something out from the code you provided most likely but I am really a beginner so I cannot.

Thank you again!

Best regards.

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: ssget filter hyperlink
« Reply #5 on: September 13, 2022, 10:41:26 AM »
After the sssetfirst from your suggested code, is there a way I can now get to the entityname (ename) of that entity which sssetfirst selects for me?

You can have the entity names in a list assigned to variable l as follows:
Replace this
Code - Auto/Visual Lisp: [Select]
  1. (or (member '(1000 . "Test-EG-001") (cdadr (assoc -3 (entget e '("PE_URL")))))
  2.        (ssdel e s)
  3.       )
  4.  
With this.
Code - Auto/Visual Lisp: [Select]
  1.  (or (and (member '(1000 . "Test-EG-001") (cdadr (assoc -3 (entget e '("PE_URL")))))
  2.           (setq l (cons e l)) ;; entity names in this list
  3.           )
  4.      (ssdel e s)
  5.      )
  6.  

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #6 on: September 14, 2022, 03:38:43 AM »
Thank you!
Now I have the entity name in l inside brackets.
I just need to remove the brackets now to be able to use it.

What is the most straight-forward way to do that?

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: ssget filter hyperlink
« Reply #7 on: September 14, 2022, 03:55:51 AM »
Thank you!
Now I have the entity name in l inside brackets.
I just need to remove the brackets now to be able to use it.

What is the most straight-forward way to do that?

You're welcome.

You don't need to remove anything but you need to use any of cycling functions like foreach, mapcar with lambda, repeat, or while ... etc.

If you are green with AutoLISP then use foreach which is clear enough.
like:
Code - Auto/Visual Lisp: [Select]
  1. (foreach entity l
  2.  ;;.... then the variable 'entity' would obtain the first element from the list 'l' then process to next .... up to the end of the list
  3. )

There are hundreds if not thousands of examples of foreach function over there .

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #8 on: September 14, 2022, 07:10:28 AM »
It seems I have a new problem.
This line here:
(or (and (member '(1000 . "Test-EG-004") (cdadr (assoc -3 (entget e '("PE_URL")))))

instead of the "Test-EG-004", i am using a variable in which I have previously saved the hyperlink, which is always different.
Somehow then it doesn't work? Can I not use a variable here?

It looks like this:
(or (and (member '(1000 . aks) (cdadr (assoc -3 (entget e '("PE_URL")))))

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #9 on: September 14, 2022, 08:58:18 AM »
I am uploading my lsp.file and dwg which I used for testing.

Here's some background info to understand what I'm trying to do:
I always have the same amount of MPOLYGON entities and block inserts with attributes. The value of the attribute "AKS_NUMMER" is always also found in the corresponding MPOLYGON's hyperlink.

In AutoCAD there is a thing called fields. What I want to do with fields is to link the area value of the MPOLYGON with the corresponding block insert (attribute "FLAECHE").
This would make it so that if the MPOLYGON is enlarged or shrinked, then the corresponding attribute will be updated automatically (or at least after regen command).

I know I can automate the creation of a field since it uses a long string called "field expression" by ACAD.
One part of the field expression is an object id (in my case id of the MPOLYGON) which I can get by converting the entity name. Once I have the field expression string I will make that the new value of the attribute "FLAECHE" and linking is complete.
I know that this is possible. I was able to create the field using some days ago but it worked only for 1 MPOLYGON but I need it to do it for all block inserts and their corresponding MPOLYGONs.

As you can see from my code I start by making a selection set of all the block inserts. Once I needed to find the corresponding MPOLYGON (the one with the same "AKS_NUMMER" as the block insert) I ran into trouble and that's when I started this thread initially.

I hope this makes sense and someone can tell me exactly which part of my code I need to change to make this work please?

Thanks again in advance!

Greetings!

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: ssget filter hyperlink
« Reply #10 on: September 14, 2022, 10:35:17 AM »
It looks like this:
(or (and (member '(1000 . aks) (cdadr (assoc -3 (entget e '("PE_URL")))))

once you have / use a variable then you should not use quote ( ' ) symbol otherwise it won't be evaluated, so note the follow use with cons function to build a dotted pair.

Code - Auto/Visual Lisp: [Select]
  1. (or (and (member (cons 1000 aks) (cdadr (assoc -3 (entget e '("PE_URL")))))
  2.  

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #11 on: September 16, 2022, 05:37:31 AM »
It looks like this:
(or (and (member '(1000 . aks) (cdadr (assoc -3 (entget e '("PE_URL")))))

once you have / use a variable then you should not use quote ( ' ) symbol otherwise it won't be evaluated, so note the follow use with cons function to build a dotted pair.

Code - Auto/Visual Lisp: [Select]
  1. (or (and (member (cons 1000 aks) (cdadr (assoc -3 (entget e '("PE_URL")))))
  2.  


Thank you!
Now my program works as it should. Although there is one unexpected side effect.
After I regen my block inserts are now stuck behind the Polygon object permanently in regards to the draw order.
Even if I select all polygons and set their draw order to the back, it doesn't change anything.

It's my lisp that triggers it and it's consistent but I don't understand how it happens or how to stop it.

Do you have any ideas perhaps?

Thanks again!

Tharwat

  • Swamp Rat
  • Posts: 684
  • Hypersensitive
Re: ssget filter hyperlink
« Reply #12 on: September 16, 2022, 06:46:50 AM »
You're welcome anytime.

After I regen my block inserts are now stuck behind the Polygon object permanently in regards to the draw order.
Try to reverse the order by moving the opposite objects to Front order or use the other available option Bring Above Objects.

It's my lisp that triggers it and it's consistent but I don't understand how it happens or how to stop it.
If you control the order from your program then you need to revise your program otherwise the order command can solve this issue.

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget filter hyperlink
« Reply #13 on: September 16, 2022, 07:18:40 AM »
It's weird, the regular draw order menu of commands didn't do anything and my program didn't include anything to change draw order at all.

However I now seem to have solved it by including a (setvar "DRAWORDERCTL" 0)  :-)