![]() |
【转帖】decal macro
decal macro
hi, i have an urgent need to get a macro working, well everything works fine except for one thing - this is an example from the api help to add a decal to a selected face - but the fitwidth and fitheight properties that are set to true don't actually check the boxes in the decal/mapping properties. i ned to get this working asap or face a lot of manual decal editing. here is the code from the api help, which if you try it you will see that those 2 properties are not set properly. '-------- ' ' preconditions: part document is open that ' contains a model. a face on the ' model is selected. photoworks ' was selected as an add-in ' in solidworks (select tools, ' add-ins, photoworks) ' ' postconditions: decal is applied to the selected ' face. ' '-------- option explicit dim swapp as sldworks.sldworks dim swmodel as sldworks.modeldoc2 dim swselmgr as sldworks.selectionmgr dim swmodeldocext as sldworks.modeldocextension dim swface as sldworks.face2 dim swdecal as sldworks.decal dim swmaterial as sldworks.rendermaterial dim boolstatus as boolean dim strname as string dim ndecalid as long sub main() set swapp = application.sldworks set swmodel = swapp.activedoc set swselmgr = swmodel.selectionmanager set swmodeldocext = swmodel.extension set swface = swselmgr.getselectedobject6(1, -1) swmodel.clearselection2 true ' apply the decal set swdecal = swmodeldocext.createdecal set swmaterial = swdecal boolstatus = swmaterial.addentity(swface) strname = "c:\program iles\solidworks\solidworks\data\graphics\decals\logos\sw.p2d" swmaterial.filename = strname strname = "c:\program iles\solidworks\solidworks\data\graphics\decals\logos\sw.bmp" swmaterial.texturefilename = strname swmaterial.mappingtype = 0 swmaterial.fixedaspectratio = false swmaterial.fitheight = true swmaterial.fitwidth = true boolstatus = swmodeldocext.adddecal(swdecal, ndecalid) ' rebuild the model to show the newly applied decal call swmodel.rebuild(swrebuildall) end sub scott nelson (zander) nelson parametrics you are correct it does not check the boxes. you may also notice it does not set the fixedaspectratio to anything either. the odd thing is if you get the decal again through code and check the properties they are actually set correctly: set swdecal = swmodeldocext.createdecal set swmaterial = swdecal swmaterial.filename = "c:\program files\solidworks\solidworks\data\graphics\decals\logos\sw.p2d" swmaterial.texturefilename = "c:\documents and settings\lukem\my documents\my pictures\bsod.bmp" swmaterial.mappingtype = 0 ' label/surface swmaterial.fixedaspectratio = true swmaterial.fitheight = true swmaterial.fitwidth = true swmaterial.addentity swface boolstatus = swmodeldocext.adddecal(swdecal, swdecal.decalid) set swdecal = swmodeldocext.getdecal(swdecal.decalid, "") set swmaterial = swdecal msgbox swmaterial.fitwidth i am guessing you are required to select the face and give it a mask id for the function to pick up on the face correctly to map to it, but i have tried a load of mask ids and combinations to no avail. also, remove the clearselections code for now as it will benefit the code trying to solve it when the face is still selected. you should drop a line to apisupport@solidworks.com they should be able to solve it for you. edited: 09/26/2008 at 05:31 am by luke malpass quick |
所有的时间均为北京时间。 现在的时间是 04:35 AM. |