See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Is it possible to use Object specific fields in a lisp

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Is it possible to use Object specific fields in a lisp

    Hey All

    Ive got an idea of what I would like to do but the first flaw I cant seem to find a way over is the use of a field in the lisp routine.
    Ideally what I would like to do is:
    Pick a block
    Insert a multi leader or multi line text
    Insert a field looking at the attribute called DESIGNATION

    I was thinking of just using text with the attribute value but having the link between the object and its text could prove to be a much more powerful tool if it is at all possible.

    Any thoughts?

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,665
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Shouldn't be a problem, could you attach a small dwg with the block, attribute, multi leader or multi line text how you want them to end up so we can see exactly what you want it to do?

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    I think it's a wrong way, if you will lost your block instance say remove them etc,
    so your field will be unreadable, use instead direct way to populate mleader with
    attribute value, though Tom's suggestion has a reason of course
    Just from a scratch:
    Using textstring value
    Code:
    (defun c:mlb (/ attribs blk_obj mlead p1 p2 ptlist pts sset txtstring)
      (vl-load-com)
    
      (prompt "\n	Select block:")
      (while
    
        (setq sset (ssget "_+.:s:l"
    		      (list (cons 0 "insert")
    			    (cons 66 1)
    			    (cons 2 "`*U*,MM_Duct_Equipment_VAV")	; <-- your block name,added "`*u*" if dynamiic block
    		      ) ;_ end of list
    	       ) ;_ end of ssget
        ) ;_ end of setq
         (progn
           (setq blk_obj (vlax-ename->vla-object (ssname sset 0)))
           (setq attribs (vlax-invoke blk_obj 'getattributes))
       (foreach	att_obj	attribs		 
    		(cond ((eq "DESIGNATION" (vla-get-tagstring att_obj) )
    		       (setq txtstring (vla-get-textstring att_obj))
    		      )
    		(T nil));_ end of cond
    	 )
    
           (setq p1	    (cadr (last (last (ssnamex sset))))
    	     p2	    (getpoint p1 "\nPick mleader text line point: ")
    	     ptlist (list p1 p2)
    	     pts    (vlax-make-variant
    		      (vlax-safearray-fill
    			(vlax-make-safearray
    			  vlax-vbdouble
    			  (cons 0 (1- (* 3 (length ptlist))))
    			) ;_ end of vlax-make-safearray
    			(apply 'append ptlist)
    		      ) ;_ end of vlax-safearray-fill
    		    ) ;_ end of vlax-make-variant
           ) ;_ end of setq
    
           (setq mlead (vla-addmleader
    		     (vla-get-modelspace
    		       (vla-get-activedocument (vlax-get-acad-object)))	;get modelspace object
    		     pts
    		     0
    		   ) ;_ end of vla-addmleader
           );_ end of setq
           (vla-put-textstring mlead txtstring)
    
         ) ;_ end of progn
      ) ;_ end of while
    
      (princ)
    ) ;_ end of defun
    
    (prompt "\n")
    (prompt "\t\t<<< start command with MLB ...\t>>> ")
    (prin1)
    Here is code to use field if you wanted be

    Code:
    (defun c:mlf (/ attribs  blk_obj Get-ObjectID-x86-x64 mlead p1 p2 ptlist pts sset txtstring)
      (vl-load-com)
    ;; from http://forum.dwg.ru/showthread.php?t=51822&highlight=GetObjectIdString
    ;;--------------------------------------------------------
    ;; get ObjectID irrespective of the version
    ;; for AutoCAD x86 or x64
    ;; source: https://discussion.autodesk.com/forums/message.jspa?messageID=6172961
    ;;--------------------------------------------------------
    (defun Get-ObjectID-x86-x64  (obj / util)
      (setq	util (vla-get-Utility
    	       (vla-get-activedocument (vlax-get-acad-object))))
      (if (= (type obj) 'ENAME)
        (setq obj (vlax-ename->vla-object obj)))
      (if (= (type obj) 'VLA-OBJECT)
        (if	(> (vl-string-search "x64" (getvar "platform")) 0)
          (vlax-invoke-method
    	util
    	"GetObjectIdString"
    	obj
    	:vlax-False)
          (rtos (vla-get-objectid obj) 2 0)
          )
        )
      )
    
      (prompt "\n	Select block:")
      (while
    
        (setq sset (ssget "_+.:s:l"
    		      (list (cons 0 "insert")
    			    (cons 66 1)
    			    (cons 2 "`*U*,MM_Duct_Equipment_VAV")	; <-- your block name,added "`*u*" if dynamiic block
    		      ) ;_ end of list
    	       ) ;_ end of ssget
        ) ;_ end of setq
         (progn
           (setq blk_obj (vlax-ename->vla-object (ssname sset 0)))
           (setq attribs (vlax-invoke blk_obj 'getattributes))
           (foreach	att_obj	attribs		 
    		(cond ((eq "DESIGNATION" (vla-get-tagstring att_obj) )
    		       (setq att_id (Get-ObjectID-x86-x64 att_obj))
    		      )
    		(T nil);_ end of cond
    	 )
           );_ end of foreach
    
           (setq p1	    (cadr (last (last (ssnamex sset))))
    	     p2	    (getpoint p1 "\nPick mleader text line point: ")
    	     ptlist (list p1 p2)
    	     pts    (vlax-make-variant
    		      (vlax-safearray-fill
    			(vlax-make-safearray
    			  vlax-vbdouble
    			  (cons 0 (1- (* 3 (length ptlist))))
    			) ;_ end of vlax-make-safearray
    			(apply 'append ptlist)
    		      ) ;_ end of vlax-safearray-fill
    		    ) ;_ end of vlax-make-variant
           ) ;_ end of setq
    
           (setq mlead (vla-addmleader
    		     (vla-get-modelspace
    		       (vla-get-activedocument (vlax-get-acad-object)))	;get modelspace object
    		     pts
    		     0
    		   ) ;_ end of vla-addmleader
           );_ end of setq
           ;(vla-update mlead)
           (vla-put-textstring mlead (strcat "%<\\AcObjProp Object(%<\\_ObjId " att_id ">%).TextString>%"))
    
         ) ;_ end of progn
        
        (command "ddedit" "_L" );; just to open text editor to force updateing field
        (command \U+001B); perform Cancel command
      ) ;_ end of while
    
      (princ)
    ) ;_ end of defun
    
    (prompt "\n")
    (prompt "\t\t<<< Start command with MLF ...\t>>> ")
    (prin1)
    Last edited by fixo; 2013-04-04 at 05:50 AM. Reason: bad code removed

  4. #4
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Tom
    Ive attached an example of one of the blocks.

    Fixo
    Cheers for the code mate, its much a appreciated.
    When I get a sec ill have a look through it and modify to suit.
    Thanks for highlighting the point about the field breaking with the deletion of a block.
    Its a valid point but for what i plan of using it for I think that it is actually a benefit.
    It allows us to see when object have been deleted and highlights issues immediately where tags need to be either deleted or reassocited.

    Cheers for the help fellas.
    Attached Files Attached Files

  5. #5
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Hey Fixo

    The Code you have written keeps giving me the error:
    bad argument type: stringp nil

    Ive looked through the code and for the life of me I can seem to find anything that might be breaking.
    Ive also checked the block and it all seems to be ok.

    If you wouldnt mind having another look at it with the previously attached block it would be much appreciated.

    Cheers

  6. #6
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Well, you're right this code is working on my dummy block,
    but for your blocks try edited lisps above,
    let me know how how this works,

    Cheers

  7. #7
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Cheers mate

    It worked like a charm.
    Only fault i could find was that the text seemed to flip back on its self when drawn on the left side of the block.
    Either way this is Awesome!
    Thanks again.
    Last edited by matthew.e.mortimer342462; 2013-04-04 at 06:53 AM. Reason: Im an idiot

  8. #8
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Hey Fixo...

    Quote Originally Posted by fixo View Post
    Code:
    (ssget "_+.:s:l" ...
    Can you explain the use of what appears to be an undocumented feature "_+.:s:l"

    In the vlide help the +, ., and :l are not listed in the help.

    Can you share your reference?

    Peter
    AutomateCAD

  9. #9
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Another thing I noticed was itoa returns the 64 bit object id

    Code:
    (itoa (vla-get-objectid objItem))
    instead of

    Code:
    (vlax-invoke-method
     (vla-get-Utility
      (vla-get-activedocument
       (vlax-get-acad-object)))
     "GetObjectIdString"
     objItem
     :vlax-False
    )
    AutomateCAD

  10. #10
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Is it possible to use Object specific fields in a lisp

    Sorry for the belating, in addition
    :L means selection on locked layers
    Regards,

    Oleg

Page 1 of 2 12 LastLast

Similar Threads

  1. 3D Section Box, only specific object
    By DaleSmith in forum Revit Architecture - General
    Replies: 3
    Last Post: 2012-01-24, 04:01 PM
  2. object specific right click menu
    By cparvez in forum AMEP General
    Replies: 2
    Last Post: 2009-07-27, 07:57 PM
  3. How to turn a mass object into a specific item
    By abink in forum Revit Architecture - General
    Replies: 5
    Last Post: 2006-10-14, 12:41 AM
  4. Can i put a label on a specific object style ?
    By daniel.hurtubise70031 in forum Revit Architecture - General
    Replies: 2
    Last Post: 2005-04-16, 08:19 PM
  5. Object specific underlay on other views
    By Chad Smith in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2003-11-25, 06:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •