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

Thread: Error on Small Code Change, Can't Figure It Out...

  1. #1
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Question Error on Small Code Change, Can't Figure It Out...

    Hey All,

    I'm trying to make (what seems like) a small change to this code, but I get an error returned when I used the modified version. I'm trying to look at the "model" number and determine which vis state to use. The code I'm beginning with only inserts the block with a pre-defined vis state.

    Code:
    "Error: bad function: #<VLA-OBJECT IAcadBlockReference2 000000003d5c0b78>"
    Here's the code that works:

    Code:
    (if		  (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		  (xins:putdynamicproperty tmp "Visibility1" "COPELAND RECIP")
           		)
    When I change the above to this, I get an error.

    Code:
    (cond
    		   (
    		   (and (setq blk "M-GROUP-CLD-XML")
    		          (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		          (or  (= (substr (xins:assoc "model" com) 1 2) "2D") ;; Copeland Recip - starts with "2D" or "3D"
    			        (= (substr (xins:assoc "model" com) 1 2) "3D")
    		          )
    		   )
    				(
    		   		(setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		  		(setq vst "COPELAND RECIP")
    		  		(xins:putdynamicproperty tmp vis vst)
    				)
    		  )
    		  
    		  (
    		   (and (setq blk "M-GROUP-CLD-XML")
    		        (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    			(or	(= (substr (xins:assoc "model" com) 1 2) "4D") ;; Copeland Recip - starts with "4D" or "6D"
    				(= (substr (xins:assoc "model" com) 1 2) "6D")
    			        )
    		   )
    		  		(
    				(setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		  		(setq vst "COPELAND RECIP - VA")
    		  		(xins:putdynamicproperty tmp vis vst)
    				)
    		  )
    		)
    
    (defun xins:putdynamicproperty (block propname value / p)
      (if (setq p (vl-remove-if-not
    		'(lambda (x) (wcmatch (strcase (vla-get-propertyname x)) (strcase propname)))
    		(vlax-invoke block 'getdynamicblockproperties)
    	      )
          )
        (vl-catch-all-apply 'vlax-put (list (car p) 'value value))
      )
    )
    This function returns the model name, which I know works because I use it elsewhere in the code. It returns something like "4DJNR28ML-TSK-C27"
    Code:
    (xins:assoc "model" com)
    Even if I change it and replace it with something like this (for testing), I get the same error.
    Code:
    (setq comp "4DJNR28ML-TSK-C27")
    Is there any hope for me?

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    Okay, I read through the linked post (and the one linked inside that), but I see a couple problems: 1.) The code that you posted is a little advanced for me, so it makes it hard to deconstruct it to just set the state. 2.) I tried LM's code, but get the same error when I replace my other subroutine with his (Error: bad function: #<VLA-OBJECT IAcadBlockReference2 00000000388226c8>). This, and what I've listed below, has led me to believe it's not the vis state that messing up, but some other part of the code.

    Big hint?
    Code:
    ; warning: local variable used as function: TMP
    I've found it stems from the OR statement like that below. I replaced "(xins:assoc "model" com)" with (setq comp "4DJNR28ML-TSK-C27") and it gives me a similar error "Error: bad function: "4DJNR28ML-TSK-C27""

    Code:
    (and (setq blk "M-GROUP-CLD-XML")
    		   (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		   (or  (= (substr (comp) 1 2) "2D") ;; Copeland Recip - starts with "2D" or "3D"
    			(= (substr (comp) 1 2) "3D")
    		   )
    		)
    Overall, I don't see why the original code I posted doesn't work. I've got a block name and a visibility state. The first code that works is a simple IF statement: If we insert this block, set it's visibility state to "X". But if I try to change this to a COND statement and add a few simple tests, it fails. I like using the COND statement because it seems easier for me to read and modify (I've got a bunch of conditionals to address). It seems like it should be simple: If a string contains a defined set of characters, set visibility of a block to X...

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    It's not as simple as it might seem; you have to test that the desired Visibility State is a member of the Allowed Values, etc. first... Backing up for a moment....

    If:
    Code:
    (setq comp "4DJNR28ML-TSK-C27")
    ... Then (you're using a variable, not calling a sub-function):
    Code:
    (and (setq blk "M-GROUP-CLD-XML")
    		   (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		   (or  (= (substr comp 1 2) "2D") ;; Copeland Recip - starts with "2D" or "3D"
    			(= (substr comp 1 2) "3D")
    		   )
    		)
    ... Or simpler still:
    Code:
    (wcmatch (substr comp 1 2) "2D,3D")
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    Quote Originally Posted by BlackBox View Post
    It's not as simple as it might seem; you have to test that the desired Visibility State is a member of the Allowed Values, etc. first... Backing up for a moment....

    If:
    Code:
    (setq comp "4DJNR28ML-TSK-C27")
    ... Then (you're using a variable, not calling a sub-function):
    Code:
    (and (setq blk "M-GROUP-CLD-XML")
    		   (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		   (or  (= (substr comp 1 2) "2D") ;; Copeland Recip - starts with "2D" or "3D"
    			(= (substr comp 1 2) "3D")
    		   )
    		)
    ... Or simpler still:
    Code:
    (wcmatch (substr comp 1 2) "2D,3D")
    I like the wcmatch, it makes sense, but I'm not sure I quite follow the rest. Wouldn't I need a variable (a string) instead of a subfunction to search as part of my IF statement?

    EDIT: Also, Lee Mac's code seems to check for AllowedValules in his subroutine:
    Code:
    (defun LM:SetVisibilityState ( block value )
        (
            (lambda ( name value )
                (vl-some
                    (function
                        (lambda ( prop )
                            (if
                                (and
                                    (eq name (vla-get-propertyname prop))
                                    (member value (mapcar 'strcase (vlax-get prop 'allowedvalues)))
                                )
                                (progn
                                    (vla-put-value prop
                                        (vlax-make-variant value (vlax-variant-type (vla-get-value prop)))
                                    )
                                    value
                                )
                            )
                        )
                    )
                    (vlax-invoke block 'getdynamicblockproperties)
                )
            )
            (LM:GetVisibilityParameterName block) (strcase value)
        )
    )
    Last edited by stusic; 2013-05-29 at 01:58 PM.

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    Quote Originally Posted by stusic View Post
    I'm not sure I quite follow the rest. Wouldn't I need a variable (a string) instead of a subfunction to search as part of my IF statement?
    You stated that you used Setq to give the comp variable a string value of "4DJNR28ML-TSK-C27"... But in your code above, you call (comp) as if it were a sub-function without any parameters... Simple replace (comp) with comp.

    In order for (comp) to return the same value, you would instead have to use:
    Code:
    (defun comp () "4DJNR28ML-TSK-C27")
    ... Which is not necessary.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    Quote Originally Posted by BlackBox View Post
    You stated that you used Setq to give the comp variable a string value of "4DJNR28ML-TSK-C27"... But in your code above, you call (comp) as if it were a sub-function without any parameters... Simple replace (comp) with comp.
    Okay, I see. Learned something new today. That happened as I was trying to find the error. The original (which I ultimately need to keep) is a function which pulls a model number from a list and was like:
    Code:
    (xins:assoc "model" com)
    That function returns something like "4DJNR28ML-TSK-C27", so I was using that to eliminate the possibility of it being the ins:massoc function causing the problem. That's where I messed up.

    So, after I've used the wcmatch to make the code a little closer to "proper", and see the subroutine checks for allowed values, and have eliminated the parens around "comp" (or replaced the whole shebang with (xins:assoc "model" com), like its supposed to be). It still craps out. WTF is wrong?! The thing is, I can use:
    Code:
    (if (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
    		 (xins:putdynamicproperty tmp "Visibility1" "COPELAND RECIP")
           		)
    But I can't seem to add any other conditional statements to change the "COPELAND RECIP" part...

  8. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    The code that is working is checking to see if a block instance was successfully placed. It is then setting a specific visibility parameter to a desired state.

    In your conditional tests you are setting the block name prior to insertion, the actual insertion of the block instance, and whether a "model" starts with a certain string. If all of the tests pass, you are inserting another instance of the block. You are then assigning to a variable the desired parameter state value. And then you are trying to set a dynamic property to that desired state.

    Your code does not assign the dynamic property name to the variable name you are using in the code.

    Also, each of your branches of your conditional are doing the same thing with the exception of the desired visibility state value. Maybe you should rethink the flow of your decision making in your code to reduce the redundancy.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    Opie, everything you've said makes sense. I've gone through and re-arranged it to try and get the order correct, as well as reduce the redundant code in the conditionals.

    Now, within my larger FOREACH statement, I think I've got it right the way you've directed, but I still get:
    Error: bad function: #<VLA-OBJECT IAcadBlockReference2 000000004199f7d8>

    I think I'm not passing the info correctly to Lee Mac's subroutine to change the vis state, but I'm not sure what to do...


    Code:
        (foreach com (xins:massoc "compressor" (cdr (assoc rck lst)))
    
                  ;; Set my block name for the entire conditional statement
                  (setq blk "M-GROUP-CLD-XML")
    	      
                  ;; Run the COND statement to verify which type of visibility is required and set the associated variable (vst)
    	      (cond
    		  ((wcmatch (substr (xins:assoc "model" com) 1 2) "2D,3D")	;; Copeland Recip - 2D or 3D.
    		   		(setq vst "COPELAND RECIP"))			
    		  ((wcmatch (substr (xins:assoc "model" com) 1 2) "4D,6D") ;; Copeland Recip - 4D or 6D.
    		   		(setq vst "COPELAND RECIP - VA"))		
    		)
    
                  ;; Insert the block
    	      (setq tmp (vla-insertblock spc (vlax-3d-point ins) blk scl scl scl 0.0))
                  ;; Set vis state
    	      (LM:SetVisibilityState ( tmp vst ))
    
                  ) ;; FOREACH
    Btw, the code is looking much better now.

  10. #10
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Error on Small Code Change, Can't Figure It Out...

    It appears you should remove the surrounding parenthesis to the arguments you are supplying to Lee Mac's subroutine. This should work.
    Code:
    (LM:SetVisibilityState tmp vst )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2012-11-12, 11:12 PM
  2. Set Figure Label Styles in the Figure Prefix Database
    By civil3d.wishlist1941 in forum Civil 3D Wish List
    Replies: 0
    Last Post: 2008-01-09, 09:38 PM
  3. Element is too small error message?
    By tiffany.amorgan in forum Revit Structure - General
    Replies: 2
    Last Post: 2006-10-30, 09:02 PM
  4. Error: Value too small
    By avn in forum AutoCAD Civil 3D - Corridors
    Replies: 0
    Last Post: 2006-09-20, 02:46 PM
  5. error message and I can't figure it out.
    By eleonard in forum AutoLISP
    Replies: 5
    Last Post: 2005-08-29, 11:17 PM

Posting Permissions

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