See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: CHGDYNPROP not selecting last object

  1. #1
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default CHGDYNPROP not selecting last object

    Hi gang,

    I'm cobbling together a lisp routine that draws a detail bubble and then inserts a callout block. Seems to work fine up until changing the visibility state of the last object.

    Here is the whole code with the problematic bit highlighted. Any help is appreciated.

    Code:
    (defun C:TESTBUB2( / TMP CAS NHS PLW)
    (setq CL (getvar "CLAYER"))
    (setq CAS (getvar 'cannoscalevalue))
    (setq NHS (/ 0.625 CAS))
    (setq PLW (/ NHS 10))
    (command "_.-Layer" "m" "L-DTL-BOX" "c" "5" "L-DTL-BOX" "l" "DASHED" "L-DTL-BOX" "")
    (command "_.rectang" "_f" NHS (while (> (getvar 'CmdActive) 0) (command pause)))
    (command "_.PEDIT" "L" "L" "on" "w" PLW "")
    (command "_.rectang" "_f" "0")
    (command)
    (command "_.-Layer" "m" "L-ANNO-SYMB" "c" "3" "L-ANNO-SYMB" "l" "CONTINUOUS" "L-ANNO-SYMB" "")
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Bring Detail Callout IMP r03 block into drawing ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (defun open_dbx (dwg / dbx)
    (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
    (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument"))
    (setq dbx (vlax-create-object
    (strcat "ObjectDBX.AxDbDocument."
    (substr (getvar "ACADVER") 1 2)
    )
    )
    )
    )
    (vla-open dbx dwg)
    dbx
    )
    (setq Dbx (open_dbx "//ny-fs01/cad_common$/AutoCAD 2014/Drawings/MVVA Callouts_Imperial r01.dwg"))
    (vla-CopyObjects
    Dbx
    (vlax-safearray-fill
    (vlax-make-safearray vlax-vbObject '(0 . 0))
    (list (vla-item (vla-get-blocks dbx) "Detail Callout IMP r03"))
    )
    (vla-get-blocks
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    (vlax-release-object dbx)
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Insert Detail Callout IMP r03 block ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (command ".-insert" "Detail Callout IMP r03" PAUSE "1" "1" "0")
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; change visibility state of Detail Callout IMP r03 block ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
        (defun CHGDYNPROP (Ename propname newval /  lo obj v vval sal tot i)
           ;; Changes a given variable in your block
           ;; Passed: Ename, Property Name, New value for Property
           ;;
           (setq obj (if (= (type Ename) 'vla-object)
        Ename
        (vlax-ename->vla-object Ename))
         v (vla-getdynamicblockproperties obj)
         vval (vlax-variant-value v)
         sal (vlax-safearray->list vval)
         tot (length sal)
         i 0)
           (while (< i tot)
             (if (= (vlax-get-property (nth i sal) "PropertyName") propname)
               (progn
                 (vlax-put-property (nth i sal) "Value" newval)
                 (setq i tot)
               )
               (setq i (1+ i))
             )
           )
         )
    (setq LO (entlast))
    (CHGDYNPROP LO "visibility" none) ;none is the visibility state name
    
    
    (setvar "CLAYER" CL)
    (princ)
    )

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: CHGDYNPROP not selecting last object

    This is just off the top of my head, as I have no opportunity for testing your code, but shouldn't none be a string? As in....

    Code:
    (CHGDYNPROP LO "visibility" "none")

  3. #3
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default Re: CHGDYNPROP not selecting last object

    Thanks GHarvey,

    That didn't do it. I get the same error:

    Command: TESTBUB2
    Current rectangle modes: Fillet=0'-0 5/8"
    ; error: no function definition: CHGDYNPROP

    If I try to manually issue the command I get:

    Command: CHGDYNPROP
    ; error: too few arguments

    Not sure about how to proceed. I'm so close, and yet... so far.

    Thanks for any help.
    Last edited by jpcadconsulting347236; 2014-11-05 at 06:20 PM.

  4. #4
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    1

    Default Re: CHGDYNPROP not selecting last object

    Finally got the whole thing working!!!!

    This command does the following:

    1. Creates a layer for the detail bubble
    2. Creates a layer for the callout tag
    3. Draws the detail bubble based on two picked points
    4. Sets the width and fillet radius of the rectangle according to the current annotation scale (so it always reads 1/16" wide with 5/8" fillets radii - in this case)
    5. sets OSMODE to Midpoint/Endpoint
    6. Inserts the callout block
    7. Sets the Visibility of the callout block to "None" (no arrowhead)
    8. Sets the current layer and OSMODE back to what they were when we started.



    Here it is:

    Code:
    (defun C:ADB( / CL COSM FRAD CAS NHS PLW)
    
    ;;;;; Collect current layer, and OSMODE settings
    (setq CL (getvar "CLAYER"))
    (setq COSM (getvar 'osmode))
    
    ;;;;; Set OSPMODE to ENDPOINT and MIDPOINT only
    (setvar 'osmode 4131)
    
    ;;;;; Collect current annotation scale value and create Values for POLYLINE WIDTH width and FILLET RADIUS
    (setq CAS (getvar 'cannoscalevalue))
    (setq NHS (/ 1 CAS))
    (setq PLW (* NHS 0.0625))
    (setq FRAD (* 10 PLW))
    
    
    ;;;;; Creat layer for the detail box and make it current
    (command "_.-Layer" "m" "L-DTL-BOX" "c" "5" "L-DTL-BOX" "l" "DASHED" "L-DTL-BOX" "")
    (setvar 'CLAYER "L-DTL-BOX")
    
    ;;;;; Draw the box using pline width and fillet radius values
    (command "_.rectang" "_f" FRAD (while (> (getvar 'CmdActive) 0) (command pause)))
    (command "_.PEDIT" "L" "L" "on" "w" PLW "")
    (command "_.rectang" "_f" "0")
    (command)
    
    ;;;;; Create the layer fo the detail tag and make it current
    (command "_.-Layer" "m" "L-ANNO-SYMB" "c" "3" "L-ANNO-SYMB" "")
    (setvar 'CLAYER "L-ANNO-SYMB")
    
    
    ;;;;; Bring in block Detail Callout IMP r03 block from MVVA Callouts_Imperial r01.dwg
    (defun open_dbx (dwg / dbx)
    (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
    (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument"))
    (setq dbx (vlax-create-object
    (strcat "ObjectDBX.AxDbDocument."
    (substr (getvar "ACADVER") 1 2)
    )
    )
    )
    )
    (vla-open dbx dwg)
    dbx
    )
    (setq Dbx (open_dbx "//ny-fs01/cad_common$/AutoCAD 2014/Drawings/MVVA Callouts_Imperial r01.dwg"))
    (vla-CopyObjects
    Dbx
    (vlax-safearray-fill
    (vlax-make-safearray vlax-vbObject '(0 . 0))
    (list (vla-item (vla-get-blocks dbx) "Detail Callout IMP r03"))
    )
    (vla-get-blocks
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    (vlax-release-object dbx)
    
    
    ;;;;; Insert Detail Callout IMP r03 block ;;;
    (command ".-insert" "Detail Callout IMP r03" PAUSE "1" "1" "0")
    
    
    ;;;;; Retuen current layer and OOMODE to original values
    (setvar 'CLAYER CL)
    (setvar 'OSMODE COSM)
    
    
    ;;;;; change visibility state of Detail Callout IMP r03 block to "None"
    (defun CHGDYNPROP (Ename propname newval /  lo obj v vval sal tot i)
           ;; Changes a given variable in your block
           ;; Passed: Ename, Property Name, New value for Property
           ;;
           (setq obj (if (= (type Ename) 'vla-object)
        Ename
        (vlax-ename->vla-object Ename))
         v (vla-getdynamicblockproperties obj)
         vval (vlax-variant-value v)
         sal (vlax-safearray->list vval)
         tot (length sal)
         i 0)
           (while (< i tot)
             (if (= (vlax-get-property (nth i sal) "PropertyName") propname)
               (progn
                 (vlax-put-property (nth i sal) "Value" newval)
                 (setq i tot)
               )
               (setq i (1+ i))
             )
           )
         )
    (CHGDYNPROP (entlast) "Visibility1" "None") ;none is the visibility state name
    (princ)
    )

  5. #5
    Woo! Hoo! my 1st post
    Join Date
    2009-12
    Posts
    1
    Login to Give a bone
    0

    Default Re: CHGDYNPROP not selecting last object

    Can we use "change visibility state of Detail Callout IMP r03 block to "None" part of the lisp for all blocks in drawing ?

    I tried to change (entlast) function with (ssget "_x" ) but it did'nt work.

  6. #6
    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: CHGDYNPROP not selecting last object

    Well this seems like a very common problem, so to create a general solution for this...

    Thoughts I had when writing this

    I like to create predicate (T for success and nil for failure) functions.

    I like to include error checking and trapping. (I use the errortrap function you all have seen many times)

    I like to check all the arguments, before I use them.

    I like to allow for wildcards in the string values.

    I also think this function frequently uses the last block object [hence the nil value automatically points at (entlast)].

    I like to allow for ename and vla-object arguments interchangeably.

    I also like to name my functions with the noun first and verb second DynamicPropertySet that way in my libraries all of the functions that affect Dynamic Properties for example are together.

    so...

    Code:
    ;___________________________________________________________________________________________________________
    ;
    ; Function for changing dynamic block properties with wildcards, with error checking and trapping
    ; Predcate function (returns T for success or nil for failure)
    ; Written By: Peter Jamtgaard copyright 2014 all rights reserved
    ; Syntax (dynamicpropertyset nil       "Visibilit*" "none") ; <- nil indicates last entity
    ; Syntax (dynamicpropertyset (entlast) "Visibilit*" "none")
    ; Syntax (dynamicpropertyset objBlock  "Visibilit*" "none")
    ;___________________________________________________________________________________________________________
    (vl-load-com)
    
    (defun DynamicPropertySet (objBlock strWCDynamicProperty Value / objProperty)
     (and
      (or objBlock 
          (setq objBlock (entlast))
      )
      (or (= (type objBlock) 'VLA-OBJECT)
          (and (= (type objBlock) 'ENAME)
               (setq objBlock (vlax-ename->vla-object objBlock))
          )
      )
      (= (type strWCDynamicProperty) 'STR)
      Value
      (wcmatch (vla-get-objectname objBlock) "AcDbBlockReference,AcDbMInsertBlock")
      (= (vla-get-isdynamicblock objBlock) :vlax-true)
      (apply 'or (mapcar '(lambda (objProperty)(and
                                                (wcmatch (strcase (vla-get-propertyname objProperty))
                                                         (strcase strWCDynamicProperty)
                                                )
                                                (errortrap '(vla-put-value objProperty Value))
                                               )
                          )
                          (vlax-invoke objBlock "getdynamicblockproperties")
                 )
      )
     )
    )
    
    ;___________________________________________________________________________________________________________
    ;
    ; Standardized Error Trap
    ;___________________________________________________________________________________________________________
    
    (defun ErrorTrap (symFunction / objError result X)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (X)(set X (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    Attached Files Attached Files
    AutomateCAD

Similar Threads

  1. selecting object
    By avinash patil in forum VBA/COM Interop
    Replies: 0
    Last Post: 2012-09-04, 09:34 AM
  2. Selecting Object That Was Just Created
    By sinrise in forum AutoLISP
    Replies: 7
    Last Post: 2011-09-27, 06:03 PM
  3. Selecting Object in different files opened
    By grobnik in forum VBA/COM Interop
    Replies: 2
    Last Post: 2011-06-05, 02:28 PM
  4. Replies: 4
    Last Post: 2007-04-17, 11:52 AM
  5. Selecting Object does not indicate Layer it is on
    By tmorrow91 in forum AutoCAD General
    Replies: 8
    Last Post: 2005-05-24, 10:12 PM

Tags for this Thread

Posting Permissions

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