• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

macro: help me create a simple material change and look at the parts?

  • Thread starter Thread starter reggio
  • Start date Start date
correct, I would like to keep the color that assigned me that is always different from the default of the material.
 
riproviamoci:

'associa 1.5714 (16nicr4), il colore rimane lo stesso
dim swapp as sldworks.sldworks
dim modeldoc2 as sldworks.modeldoc2
dim swcompmodel as sldworks.modeldoc2
dim swmodel as sldworks.modeldoc2
dim swselmgr as sldworks.selectionmgr
dim swcomp as sldworks.component2
dim vmatprop as variant
dim bret as boolean
dim longstatus as long, longwarnings as long
global const swdocpart = 1
global const swdocasm = 2
dim retvar as variant
dim retvar_old as variant
sub main()
set swapp = createobject("sldworks.application")
set modeldoc2 = swapp.activedoc
if modeldoc2 is nothing then
msgbox "nessun documento caricato." + chr$(10) + chr$(13) _
+ "carica un file di parte o assieme."
exit sub
end if
filetyp = modeldoc2.gettype
if filetyp = swdocpart then
modeldoc2.materialpropertyvalues = retvar
modeldoc2.editrebuild3
end if
if filetyp = swdocasm then
set swmodel = swapp.activedoc
dim i as integer
dim selcount as integer
set swselmgr = swmodel.selectionmanager
selcount = swselmgr.getselectedobjectcount()
if selcount > 0 then
for i = 1 to swselmgr.getselectedobjectcount()
set swselobj = swselmgr.getselectedobject5(i)
set swcomp = swselmgr.getselectedobjectscomponent2(i)
set swcompmodel = swcomp.getmodeldoc
dim partdoc as sldworks.partdoc
set partdoc = swcomp.getmodeldoc
retvar_old = partdoc.materialpropertyvalues
debug.print retvar_old(0)
debug.print retvar_old(1)
debug.print retvar_old(2)
vmatprop = swcompmodel.materialpropertyvalues
debug.print vmatprop(0)
debug.print vmatprop(1)
debug.print vmatprop(2)
'cambiare dicitura materiale a seconda dell'esigenza, se serve anche il percorso della libreria
partdoc.setmaterialpropertyname2 "default", "c:/program files/solidworks corp/solidworks/lang/italian/sldmaterials/solidworks din materials.sldmat", "1.5714 (16nicr4)"
'nel caso non si volesse forzare il colore del materiale commentare il codice fino a "fine commento"
'questa parte associa il colore rosso alla parte indifferentemente dal colore del materiale impostato nella scheda materiale si solidworks
'vmatprop = swcompmodel.materialpropertyvalues
retvar = partdoc.materialpropertyvalues
retvar(0) = retvar_old(0)
retvar(1) = retvar_old(1)
retvar(2) = retvar_old(2)
retvar(3) = retvar_old(3)
retvar(4) = retvar_old(4)
retvar(5) = retvar_old(5)
retvar(6) = retvar_old(6)
retvar(7) = retvar_old(7)
retvar(8) = retvar_old(8)
partdoc.materialpropertyvalues = retvar
'"fine commento"
partdoc.save2 true
next
end if
swmodel.clearselection2 true
end if
end sub
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top