Jump to content

Need help debugging this code


chiimayred

Recommended Posts

Hey guys,

 

hope your guys' summer have been awesome so far.

 

I am working on a piece of code where I can save each layout as a 2004 autocad drawing (as well as bind any xref's and purge/audit the drawing). One of our clients requires this and depending on the project size it can take a long time manually.

 

I was looking around for a code for a long time, and only one has come really close to what I was looking for... and I found it here

 

I've taken certain parts of his code and b*stardized it to fit closer to my needs. One of the reasons using "wblock" doesn't work for my case is that I have templates made up with specific fields in the custom properties menu that I need to retain.

 

Please note, this is a very rough and draft version. I haven't cleaned it up yet or added error checking yet. This was more of a tinkering/I never thought I'd be able to get it working project.

 

So I got the code working great earlier this afternoon doing what I wanted it to do perfectly. I then started to work on error checking and fancying it up a bit when all of a sudden I'm getting a new error message:

; error: no function definition: 
VLAX-GET-ACAD-OBJECT

 

I've since tried to undo/grab backups on this code and even using the restored version of the code (before this error starting showing up) and I'm still getting the same error. I don't know what's going on and I'm a bit in over my head.

 

Any help with this is appreciated.

 

(defun c:test (/)
(foreach x
 (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (410 . "MODEL")))));;select all objects
 (setq blk (cdr (assoc 2 (entget x))));;
 (if (assoc 1 (tblsearch "block" blk)) (command "_.xref" "bind" blk));;if an xref, bind into drawing
);;end foreach
 (command
   "_.audit" "_yes" ""
   "_.audit" "_yes" ""
   "-purge" "_regapps" "" "_no"
   "_.purge" "all" "" "_no"
   "_.purge" "all" "" "_no"
   "_.purge" "all" "" "_no"
   );;end command
(defun DelAllLayouts (Keeper / TabName)
   (vlax-for Layout
     (vla-get-Layouts
       (vla-get-activedocument (vlax-get-acad-object))
     )
     (if
       (and
         (/= (setq TabName (strcase (vla-get-name layout))) "MODEL")
         (/= TabName (strcase Keeper))
        )
          (vla-delete layout)
      )
    )
 );;end delalllayouts command
  (command "._undo" "_BE")
  (setq dn (getstring "Enter Filename: "))
   (foreach lay (layoutlist)
     (setq path (getvar "DWGPREFIX"));;get filepath of the current drawing
  (setq filename (strcat path dn lay ".dwg"))
   (if (and (/= lay "Model")
            (> (vla-get-count (vla-get-block
                 (vla-Item (vla-get-Layouts
                   (vla-get-activedocument (vlax-get-acad-object))) lay))) 1))
     (progn
(command "_.undo" "_M")
       (DelAllLayouts lay)
       (setvar "tilemode" 1)
       (command "_.ucs" "_w")
       (setvar "tilemode" 0)
(command
 "_.zoom" "extents"
 "_.saveas" "2004" filename
 "_.undo" "_b"
 )
)
     );;end if
     );; end foreach
 );;end defun
 

Link to comment
Share on other sites

Perhaps

(vl-load-com)

 

HTH

Henrique

 

That seems to have done the trick... I can't believe I missed something so simple.

 

Thanks Henrique!

Link to comment
Share on other sites

Hey,

 

So with the drawings we have here, we use custom properties to set the revision number. I want to be able to add the revision number to the filename itself. I'm having a hard time trying to figure out how to get the value of that custom property and set it to a variable.

 

(defun c:test ()
 (vl-load-com)
 (setq acadObject (vlax-get-Acad-Object))
 (setq acadDocument (vla-get-Activedocument acadObject))
 (setq dProps (vlax-get-property acadDocument 'Summaryinfo))
 (setq revnumber (vla-getcustombyindex dprops 6 ))
 (alert revnumber)
 )

 

Here's my shot at it but I get this error:

 

Command: test ; error: too few actual parameters

 

it is the 6th custom property and the name of the property is "rev."

Link to comment
Share on other sites

Hey,

 

So with the drawings we have here, we use custom properties to set the revision number. I want to be able to add the revision number to the filename itself. I'm having a hard time trying to figure out how to get the value of that custom property and set it to a variable.

 

(defun c:test ()
 (vl-load-com)
 (setq acadObject (vlax-get-Acad-Object))
 (setq acadDocument (vla-get-Activedocument acadObject))
 (setq dProps (vlax-get-property acadDocument 'Summaryinfo))
 (vla-getcustombyindex dprops 6 'key6 'revnumber)
 (alert revnumber)
 )

 

Here's my shot at it but I get this error:

 

Command: test ; error: too few actual parameters

 

it is the 6th custom property and the name of the property is "rev."

 

 

Nevermind, figured it out!

Edited by chiimayred
updated code to reflect the correction
Link to comment
Share on other sites

Hey,

 

More or less completed the code, however there's one error check I don't know how to do. Similar to the previous post, the revision number is a custom property in the drawing, again the 6th one. Some of our older drawings or some we get from other firms do not have this setup. I want to check to see if the custom property is there and if not the user will be prompted to input it manually.

 

I'm having a tough time trying to figure out how to check for the custom property.

 

I took some code from here. When I test it with a drawing with the custom property present, it still prompts for the manual revision input instead of getting the custom property.

 

Here is the code in question, slightly customized from the link above for my purposes.

 

(vl-load-com)
(DEFUN C:TEST (/)
 (setq acadObject (vlax-get-Acad-Object))
 (setq acadDocument (vla-get-Activedocument acadObject))
 (setq dProps (vlax-get-property acadDocument 'Summaryinfo)
(setq KeyName "rev.")
(setq Keycount 6)
(setq KeyValue nil)
 (while (and (null KeyValue) (< KeyCount (vla-NumCustomInfo dprops)))
   (vla-GetCustomByIndex
     dprops
     KeyCount
     'TempKeyName
     'TempKeyValue);vla
   (if
     (= TempKeyName KeyName) (setq KeyValue TempKeyValue))
   (setq KeyCount (1+ KeyCount))
   );while
     (if (= KeyValue nil)
  (setq rev (getstring "\nWhat is Rev? "))
  ()
  )
   );end defun

 

Thanks again!

 

edit: figured out my error, the KeyName variable at the top was a typo... works good now.

Edited by chiimayred
spelling, code correction
Link to comment
Share on other sites

Use the Tag name method to find an attribute then you only need to enterthe name of the consultants tag then your code will work with theres.

 

;example only of method cut from bigger program bits missing
(setq oldtag1 "DRAWING_STATUS") ;attribute tag name
(setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "DA1DRTXT"))))
(setq inc (sslength ss1))
(repeat inc      
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(setq tagans (vla-get-textstring att)) 
) ; end if

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...