Jump to content
K Baden

Too many arguments issue

Recommended Posts

Good morning all!

I am having trouble figuring out how i should properly fix the following code. I am getting too many arguments in the section highlighted, which makes sense to me but im not entirely sure what to do to fix. do i need to add a progn before the changes? Any help would be appreciated!

 

I basically want it to catch all hatch inside blocks that are on that specific layer, and Solid, then change the pattern, scale, and background color of each. I think i have the right process, but I don't think if/and is correct when i have 3 qualifiers. Thanks in advance for any help!

 

(defun c:planproposedhatch (/ doc)
 (or *colorobject*
     (setq *colorobject*
     (vla-getinterfaceobject
       (vlax-get-acad-object)
       (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
     )
     )
 )
 (if
   (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
    (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-Activedocument (vlax-get-acad-object))))
      (if (= :vlax-false (vla-get-isxref blk))
	(vlax-for obj blk
	  (if (and (= "08_Proposed Data" (strcase (vla-get-layer obj)))
		   (= "AcDbHatch" (vla-get-objectname obj))
		   (= "SOLID" (strcase (vla-get-patternname obj)))
		   (vlax-write-enabled-p obj)
	      )
	    (vl-catch-all-apply 'vla-put-patternname obj ANSI31)
	    (vl-catch-all-apply 'vla-put-ScaleFactor obj 12)
	    (vl-catch-all-apply 'vla-put-backgroundcolor (list obj *colorobject*))
	  )
	)
      )
    )
    (vla-regen doc acallviewports)
    )
 )
 (princ)
)
(vl-load-com)
(princ)

Share this post


Link to post
Share on other sites

Hi,

 

If you would like to implement more actions than once with if function then you need to use progn function.

 

[color="blue"](progn[/color]
                   (vl-catch-all-apply 'vla-put-patternname obj ANSI31)
	    (vl-catch-all-apply 'vla-put-ScaleFactor obj 12)
	    (vl-catch-all-apply 'vla-put-backgroundcolor (list obj *colorobject*))
[color="blue"])[/color]

Share this post


Link to post
Share on other sites

You can also use COND like so:

(cond ((and (= "08_Proposed Data" (strcase (vla-get-layer obj)))
    (= "AcDbHatch" (vla-get-objectname obj))
    (= "SOLID" (strcase (vla-get-patternname obj)))
    (vlax-write-enabled-p obj)
      )
      (vl-catch-all-apply 'vla-put-patternname obj ansi31)
      (vl-catch-all-apply 'vla-put-scalefactor obj 12)
      (vl-catch-all-apply 'vla-put-backgroundcolor (list obj *colorobject*))
     )
)

Although your test will always fail here:

(= "08_Proposed Data" (strcase (vla-get-layer obj)))

Do you see why?

Share this post


Link to post
Share on other sites
Would that fail because of the strcase?

 

There is no function definition vla-put-patternname besides the other errors that described above, so try the following:

(if
   (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
    (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-Activedocument (vlax-get-acad-object))))
      (if (= :vlax-false (vla-get-isxref blk))
	(vlax-for obj blk
	  (if (and (vlax-write-enabled-p obj)
                          (= "08_PROPOSED DATA" (strcase (vla-get-layer obj)))
		   (= "AcDbHatch" (vla-get-objectname obj))
		   (= "SOLID" (strcase (vla-get-patternname obj)))   
	      )
                   (progn 
                     (vla-setPattern obj acHatchPatternTypePreDefined "ANSI31")
                     (vla-put-ScaleFactor obj 12)
	      (vla-put-backgroundcolor (list obj *colorobject*))
	  )
	)
      )
            )
    )
    (vla-regen doc acallviewports)
    )
 )

Edited by Tharwat

Share this post


Link to post
Share on other sites

You messing with him? :P

(= "08_PROPOSED DA[color="red"]t[/color]A" (strcase (vla-get-layer obj)))

Share this post


Link to post
Share on other sites
You messing with him? :P

(= "08_PROPOSED DA[color="red"]t[/color]A" (strcase (vla-get-layer obj)))

 

No. You got my wrong :lol:

Share this post


Link to post
Share on other sites

Thanks everyone! I'll give this a go and see how it works! I appreciate everyone helping out. Before it wasnt really doing anything, and I assume it is because of my incorrect vla-put-patternname. I assumed that would be the function definition simply due to how you "get" it. Thanks!! I will give this a shot!

 

Another quick question would be, if I wanted for example all blokcs that names end in "_PLAN" to have the hatch scale set to 12 and all blocks that end in "_ELEV" to set the hatch scale to 60, would that involve a (cond) surrounding the function that is updating the scale already?

Share this post


Link to post
Share on other sites

Does anyone know how to make this affect dynamic blocks as well? It seems to only be working on regular blocks, and right now it isn't changing the background color.

 

After testing and a little searching i also found that vla-put-patternscale is what i wanted rather than vla-put-scalefactor.

 

So its doing everything except adding the BG color, and it's only working on regular blocks.

 

The majority of blocks this will be changing are dynamic. Any ideas? Any advice would help! Thanks in advance.

 


(defun c:planproposedhatch (/ doc)
 (or *colorobject*
     (setq *colorobject*
     (vla-getinterfaceobject
       (vlax-get-acad-object)
       (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
     )
     )
 )
 (if
   (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
    (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-Activedocument (vlax-get-acad-object))))
      (if (= :vlax-false (vla-get-isxref blk))
	(vlax-for obj blk
	  (if (and (vlax-write-enabled-p obj)
                          (= "08_Proposed Data" (vla-get-layer obj))
		   (= "AcDbHatch" (vla-get-objectname obj))
		   (= "SOLID" (strcase (vla-get-patternname obj)))   
	      )
                   (progn 
                     (vla-setPattern obj acHatchPatternTypePreDefined "ANSI31")
                     (vla-put-patternscale obj 12)
	      (vla-put-backgroundcolor (list obj *colorobject*))
	    )
	)
      )
            )
    )
    (vla-regen doc acallviewports)
    )
 )
(vl-load-com)

(princ)
);defun

Share this post


Link to post
Share on other sites

Are you sure all your hatches are on layer "08_Proposed Data" and all layers are unlocked?

Share this post


Link to post
Share on other sites

Hmm. perhaps it is because the hatch within the block would technically be on bylayer, the block itself is on 08_Proposed Data. Perhaps the layer should be specified in the search for a selection of blocks to edit?

Share this post


Link to post
Share on other sites

I have fixed the Background color issue in the newest version of this code below. My only problem left to figure out is why it isnt working on dynamic blocks. Is there a different way to call out hatching that is dynamic within a block?

 

EDIT

You are right, it is because the hatching within the dynamic blocks are set to ByBlock layer, rather than 08_Proposed Data. I'm not understanding why/how this is specifying the layer of the hatch inside the block, rather than the block itself. where would be the spot for the layer qualifier here so that it edits all hatching inside blocks that are on the 08_Proposed Data layer?

 

I suppose from my view it should specify the layer the block is on, then specify the hatch selection within, then specifiy the SOLID hatch selection. It almost seems as though the layer qualifier is affecting the hatch within rather than the block as a whole. Any advice?

 

 

(defun c:planproposedhatch (/ doc)
 (or *colorobject*
     (setq *colorobject*
     (vla-getinterfaceobject
       (vlax-get-acad-object)
       (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
     )
     )
 )
 (if
   (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
    (progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-Activedocument (vlax-get-acad-object))))
      (if (= :vlax-false (vla-get-isxref blk))
	(vlax-for obj blk
	  (if (and (vlax-write-enabled-p obj)
                          (= "08_Proposed Data" (vla-get-layer obj))
		   (= "AcDbHatch" (vla-get-objectname obj))
		   (= "SOLID" (strcase (vla-get-patternname obj)))   
	      )
                   (progn 
                     (vla-setPattern obj acHatchPatternTypePreDefined "ANSI31")
                     (vla-put-patternscale obj 12)
	      (vl-catch-all-apply 'vla-put-backgroundcolor (list obj *colorobject*))
	    )
	)
      )
            )
    )
    (vla-regen doc acallviewports)
    )
 )
(vl-load-com)

(princ)
);defun

 

EDIT 2

 

I tried this to see if it would capture the layer property for just the blocks and got and activex Server error "unknown name: Layer"

 

(defun c:planproposedhatch (/ doc)
 (or *colorobject*
     (setq *colorobject*
     (vla-getinterfaceobject
       (vlax-get-acad-object)
       (strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
     )
     )
 )
 (if
   (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
    (progn 
    (vlax-for blk 
	(vla-get-blocks (setq doc (vla-get-Activedocument (vlax-get-acad-object))))
    [color="red"]  (if (and (= "08_Proposed Data" (vla-get-layer blk))
	  (= :vlax-false (vla-get-isxref blk))
	  )[/color]
	(vlax-for obj blk
	  (if (and (vlax-write-enabled-p obj)
		   (= "AcDbHatch" (vla-get-objectname obj))
		   (= "SOLID" (strcase (vla-get-patternname obj)))   
	      )
                   (progn 
                     (vla-setPattern obj acHatchPatternTypePreDefined "ANSI31")
                     (vla-put-patternscale obj 12)
	      (vl-catch-all-apply 'vla-put-backgroundcolor (list obj *colorobject*))
	    )
	)
      )
            )
    )
    (vla-regen doc acallviewports)
    )
 )
(vl-load-com)

(princ)
);defun

Edited by K Baden

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×