TheSwamp

Code Red => VB(A) => Topic started by: shamsam1 on July 01, 2008, 09:02:59 AM

Title: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on July 01, 2008, 09:02:59 AM
Can anyone help me to code in vba for attaching material(bmp,jpeg) to layer in autocad  and render on click of a button.Its urgent.
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: David Hall on July 01, 2008, 10:05:13 AM
what do you have so far?
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: zep6980 on July 01, 2008, 12:41:30 PM

Hey Sham

I have done these things manually but never automated the process
I agree with CM, cna you show us what you've done so far?

Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: Bob Wahr on July 01, 2008, 02:11:38 PM
Couldn't stay away, member formerly known as ML?

- EDIT -

removed first person reference by member request

- EDIT -

left first person reference out for now but regained at least some of the intent of my post
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: zep6980 on July 02, 2008, 04:42:47 PM

And what was the intent Bob?

My intent is to advance my CAD skills and try to help others as much as I can.

I don't hang onto animosity.

In the future, please feel free to pvt me anytime,  as opposed to placing none CAD related matter (such as my first name) in the post.

Thank you

Zep
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: Bob Wahr on July 03, 2008, 09:34:45 AM
I wasn't aware that calling someone by name equaled animosity.  You can read that on whatever your next account is.
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: Glenn R on July 03, 2008, 10:00:31 AM
:lmao:
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 07, 2008, 01:44:12 AM
this is what i have it work fine in autcad2007 but in 2005 some problem


(defun c:pumat(/ Lst sSet mLst cMat sCnt lCnt mCnt eCnt)

(vl-load-com)
 
  (setq Lst (list
          '("0" "Global")
      

'("Layer1" "Material 2")

      
        ); end list
            ); end setq

  (vl-load-com)
 
(if(setq sSet(ssget "_X" '((0 . "*SOLID"))))
  (progn
    (setq sCnt 0 lCnt 0)
    (vlax-for mat (vla-get-Materials
              (vla-get-ActiveDocument
           (vlax-get-acad-object)))
      (setq mLst(cons(vla-get-Name mat)mLst))
      ); end vlax-for
    (foreach itm
        (mapcar 'vlax-ename->vla-object
          (vl-remove-if 'listp
            (mapcar 'cadr(ssnamex sSet))))
         (if(setq cMat
         (cadr
           (assoc
             (setq cLay(vla-get-Layer itm))Lst)))
      (if(member cMat mLst)
        (if(vl-catch-all-error-p
             (vl-catch-all-apply 'vla-put-Material
          (list itm cMat)))
          (setq lCnt(1+ lCnt))
          (setq sCnt(1+ sCnt))
          ); end if
        (if(not(member cMat mCnt))
         (setq mCnt(cons cMat mCnt))
          ); end if
        ); end if
      (if(not(member cLay eCnt))
        (setq eCnt(cons cLay eCnt))
        ); end if
          );end if
       ); end foreach
    (if(or(/= 0 lCnt)(/= 0(length mCnt))(/= 0(length eCnt)))
      (progn
   (princ "\n========================= ERROR LIST =========================\n")
   (if(/= 0(length mCnt))
     (progn
       (princ "\nFollowing materials missed in drawing: \n")
       (foreach mat mCnt
         (princ(strcat "\n " mat))
         ); end foreach
       (princ "\n")
       ); end progn
     ); end if
       (if(/= 0(length eCnt))
     (progn
       (princ "\nSome solid layers missed in list: \n")
       (foreach lay eCnt
         (princ(strcat "\n " lay))
         ); end foreach
       (princ "\n")
       ); end progn
     ); end if
    (if(/= 0 lCnt)
      (princ(strcat "\n" (itoa lCnt) " were on locked layer!\n"))
     ); end if
   (princ "\n========================== END LIST ==========================\n")
   (textscr)
   ); end progn
      ); end if
         (princ(strcat "\n<<< Materials are appropriated for "
            (itoa sCnt) " of "
            (itoa(sslength sSet)) " solids >>>"))
    ); end progn
  (princ "\n<!> No Solids Found <!> ")
  ); end if
  (princ)
  ); end of c:pumat
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: jnieman on August 07, 2008, 12:51:58 PM
I take it you gave up on using vba :P
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 07, 2008, 01:46:30 PM
wel stil looking for vba version of the code. to attach material to layer for autcad2005 :mrgreen:
Title: Re: vba/lisp for attaching material(bmp,jpeg) to layer in autocad2005/2006
Post by: shamsam1 on August 09, 2008, 02:05:38 AM
Help me out guys to attach  material to layer in autocad2005/2006 with vba or lisp program..badly needed. :-)
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: jbuzbee on August 11, 2008, 10:07:05 AM
the Materials Collection was introduced when the render-er changed in 2007.

Materials in 2006 and earlier are defined by the old ACAD_RENDER ads program and are not accessible via activex - I don't know if there is even a command line version for attaching materials to a layer.

These are the only commands defined by the ACAD_RENDER arx:

c:3dsin, c:3dsin
    c:3dsout, c:3dsout
    c:background, c:background
    c:finish, c:finish
    c:fog, c:fog
    c:light, c:light
    c:lsedit, c:lsedit
    c:lslib, c:lslib
    c:lsnew, c:lsnew
    c:matlib, c:matlib
    c:render, c:render
    c:renderupdate, c:renderupdate
    c:rendscr, c:rendscr
    c:replay, c:replay
    c:rfileopt, c:rfileopt
    c:rmat, c:rmat
    c:rpref, c:rpref
    c:saveimg, c:saveimg
    c:scene, c:scene
    c:setuv, c:setuv
    c:showmat, c:showmat
    c:stats, c:stats
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 11, 2008, 11:28:55 AM
thanks jab jbuzbee

at least some thing i got to start with ... :roll:..wiill experiment with it tomorrow
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: jbuzbee on August 11, 2008, 11:50:43 AM
here's another thought:

could you set up a standard material/layer drawing?  have the materials already attached to the layer.  then you could import the layers via objectdbx.  You could even use a naming convention or include the material in the description:

3d-wall-stucco-red . . . "sand finish stucco with red paint finish"

??

I've got an import layers routine in AutoLISP, but it requires OpenDCL (which is free) for the GUI:

OpenDCL
http://sourceforge.net/projects/opendcl/?abmode=1 (http://sourceforge.net/projects/opendcl/?abmode=1)

Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 11, 2008, 12:10:40 PM
i have materail list and layer list ...so i just need to attach materiel to particular layer by using command which i am doing in 2007 as i pasted lisp the code above..same thing i need to do in 2005
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 11, 2008, 12:14:18 PM
in lisp i just type  pumat(layername,material )..so material get attach to particular layer
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 12, 2008, 04:44:17 AM
hi jbuzbee

i have gone through the link provide by u..but there are so many thing to download so bit confused there...
can u provide me with steps to load that dcl and use in autocad2005
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: jbuzbee on August 12, 2008, 10:03:57 AM
Go here to download the kbImportLayers.zip

http://www.theswamp.org/index.php?topic=24404.new#new (http://www.theswamp.org/index.php?topic=24404.new#new)

Go here and download the OpenDCL runtime module:

http://downloads.sourceforge.net/opendcl/OpenDCL.Runtime.ENU.4.1.2.2.msi?modtime=1208133111&big_mirror=0 (http://downloads.sourceforge.net/opendcl/OpenDCL.Runtime.ENU.4.1.2.2.msi?modtime=1208133111&big_mirror=0)

If that link doesn't work, go here and download the OpenDCL runtime - look for the file OpenDCL.Runtime.ENU.4.1.2.2.msi

http://sourceforge.net/project/showfiles.php?group_id=187950 (http://sourceforge.net/project/showfiles.php?group_id=187950)

Run the msi installer.  That will load OpenDCL onto your computer.  Now, unzip the contents of kbImportLayers.zip to it's own folder. In AutoCAD load the kbImportLayers.lsp file using whatever method you want.  Now type "kbImportLayers" at the command line.  The form should appear.

(http://i283.photobucket.com/albums/kk302/bothetraveler/kbImportLayers.jpg?t=1218549659)



Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: shamsam1 on August 13, 2008, 12:41:33 AM
jbuzbee

nice thing to import layer...

Next thing is to import material list ..if any dcl lisp is there let me know
Title: Re: vba for attaching material(bmp,jpeg) to layer in autocad
Post by: jbuzbee on August 13, 2008, 10:33:21 AM
attach the materials to the layers using the RMAT command in a "Standard Material Drawing" and put it somewhere you can find it - a support or customization drive / folder.  Then use the routine to import the layers - they'll come in with the materials attached.  That is as long as they don't exist.  This routine will not overwrite existing layers.