Put URL

Put URL

Anonymous
Not applicable
1,154 Views
7 Replies
Message 1 of 8

Put URL

Anonymous
Not applicable

Hi,

 

 

I am still a LISP novice and stuck on making the following work:

 

(defun c:link (/ ent rec fvals ATAH_HyperlinkObject)
(setq ATAH_HyperlinkObject (ssget "X"))
(if
   (member (vla-get-objectname ATAH_HyperlinkObject) '("AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc"))
(repeat (progn
   (setq ent (cons(vlax-ename->vla-object ATAH_HyperlinkObject)
           rec (ade_odgetrecord ent "Rockville_Plats" 0)
           fvals (ade_odgetrecfield rec "document_L")))
(vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject))
(vl-princ-to-string fvals))
(princ))

 

I keep getting a bad argument on VLA-OBJECT <Selection Set: x

 

The set size keeps moving around (~300 items less than the total in the dataset), too, so not only am I misplacing my repeat/cons stuff,  I think I also need additional code to handle the portions of my dataset that contain null values...?

 

The shapefile I am working with is attached.

 

I appreciate any thoughts and assistance.

 

Best,

Dan

0 Likes
Accepted solutions (1)
1,155 Views
7 Replies
Replies (7)
Message 2 of 8

Ajilal.Vijayan
Advisor
Advisor

Hi,

Can you share a sample drawing to test ?

The shapefile you have attached is a GIS shapefile ?

I think you have to attach the shapefile as a zip file contains the other associated files.

0 Likes
Message 3 of 8

roland.r71
Collaborator
Collaborator

Structure your code and you'll see you at least are missing 1 )

...but there's more...

 

The (princ) within the if statement is a 'else' currently. etc.

A progn in the wrong place and a cons i can't place...

 

(defun c:link (/ ent rec fvals ATAH_HyperlinkObject)
   (setq ATAH_HyperlinkObject (ssget "X"))
   (if (member (vla-get-objectname ATAH_HyperlinkObject) '("AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc"))
      (repeat 
         (progn
            (setq ent (cons(vlax-ename->vla-object ATAH_HyperlinkObject)
                  rec (ade_odgetrecord ent "Rockville_Plats" 0)
                  fvals (ade_odgetrecfield rec "document_L")
             )
          )
         (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject))
         (vl-princ-to-string fvals)
      )
      (princ)
   )
(defun c:link (/ ent rec fvals ATAH_HyperlinkObject)
   (setq ATAH_HyperlinkObject (ssget "X"))
   (if (member (vla-get-objectname ATAH_HyperlinkObject) '("AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc"))
      (repeat 
         (setq ent (vlax-ename->vla-object ATAH_HyperlinkObject)
               rec (ade_odgetrecord ent "Rockville_Plats" 0)
               fvals (ade_odgetrecfield rec "document_L")
         )
         (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject))
         (vl-princ-to-string fvals)
      )
   )
  (princ)
)

 

Message 4 of 8

Anonymous
Not applicable

attached is the full shape package.

0 Likes
Message 5 of 8

Anonymous
Not applicable

I am sorry about the mess, Roland.  Thank you for cleaning it up.  I am still getting hung up on the bad argument type: VLA-Object <Selection Set: x>, or if i swap out ssget "X" w/ (car (entsel "\nSelect object for hyperlink: ")) it fails on VLA-OBJECT <Entity name: x>.

 

I think I am missing something very basic about objects/entities/VLA....  If anyone can make out what I am missing I would greatly appreciate the help.  I'll continue to work at this/ bang my head on my desk in the meantime.

 

Thanks,

Dan

0 Likes
Message 6 of 8

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

I am sorry about the mess, Roland.  Thank you for cleaning it up.  I am still getting hung up on the bad argument type: VLA-Object <Selection Set: x>, or if i swap out ssget "X" w/ (car (entsel "\nSelect object for hyperlink: ")) it fails on VLA-OBJECT <Entity name: x>.

 

I think I am missing something very basic about objects/entities/VLA....  If anyone can make out what I am missing I would greatly appreciate the help.  I'll continue to work at this/ bang my head on my desk in the meantime.

 

Thanks,

Dan



it's telling you it wants a VLA-Object. Not a selection set or entity name 😉

 

Lets say you have your entity name in var 'ATAH_HyperlinkObject' :

   (setq ATAH_HyperlinkENTITY (car (entsel "\nSelect object for hyperlink: ")))

 

You need to create a VLA-Object from that first:

 

   (setq obj (vlax-ename->vla-object ATAH_HyperlinkENTITY))

 

Then pass the 'obj' to any VLA function to process it.

 

So, in this case:

    (vla-get-objectname obj)

   (vla-get-Hyperlinks obj)

 

So it becomes something like this: NOTE: I don't know if these ade_odget* functions need an vla-object...

(defun c:link (/ ATAH_HyperlinkEntity ATAH_HyperlinkObject rec fvals)
   (setq ATAH_HyperlinkEntity (car (entsel "\nSelect object for hyperlink: "))) ; get entity
(setq ATAH_HyperlinkObject (vlax-ename->vla-object ATAH_HyperlinkEntity)) ; create vla-object
(if (member (vla-get-objectname ATAH_HyperlinkObject) '("AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc")) (repeat     (setq rec (ade_odgetrecord ATAH_HyperlinkObject "Rockville_Plats" 0)         fvals (ade_odgetrecfield rec "document_L")         ) (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject)) (vl-princ-to-string fvals) ) )   (princ) )
Message 7 of 8

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

Dan,

Try with this code.

I have added the comments to explain the code.

Let me know if you need further information.

(defun c:link (/ ent obj rec i fvals ATAH_HyperlinkObject)
    (setq
        ATAH_HyperlinkObject (ssget "X");get all objects
        i 0); set the initial value for i as 0
    (repeat (sslength ATAH_HyperlinkObject);loop the selection set
        (setq
            ent (ssname ATAH_HyperlinkObject i);get the entity name from the selectionset at the index of 'i'
            obj (vlax-ename->vla-object ent) ; convert the entity to vla-object
        );setq
        (if (member (vla-get-objectname obj) '("AcDbPolyline" "AcDbLWPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc"))      
            (progn
                (setq
                    rec (ade_odgetrecord ent "Rockville_plats" 0);ade_odgetrecord requires entity name
                    fvals (ade_odgetrecfield rec "document_L")
                );setq
                (vla-Add (vla-get-Hyperlinks obj) fvals)
                (vl-princ-to-string fvals)
            );progn
        );if
    (setq i ( + 1 i));increment 'i' to get the next entity from the selection set
    );repeat
    (princ)
);defun

 

0 Likes
Message 8 of 8

Anonymous
Not applicable

Mr. Vijayan,

 

That is exactly what I was trying to do.  Your work is perfectly formatted and understandable. 

 

Thank you so much for looking into the problem.

 

Best,

Dan

0 Likes