hong Posted December 23, 2003 Share Posted December 23, 2003 I am looking for a script that allows me to create a new class and assign class attributes from the object that I select on screen. Usually I make graphic adjustments on screen with object palette and give a name later as a new classs. I am trying to see if there is a simpler way to do this. Quote Link to comment
Paolo Posted January 8, 2004 Share Posted January 8, 2004 Hi Hong, I made a script that creates a new class (naming it with a prefix and a suffix composed by line color and fill color indexes) each time a new pair pen/fill is found in the selected objects. This is useful to me to convert line-coloured 3D models (often DXFs) you find around the web and you want them to be coloured by class. Hoping this is useful, here's the code Paolo code: procedure col2class; {this procedure is to convert selected objects to a new class with prefix-indexcolor naming} {a class is created each time a new couple pen/fill is found} var prefix : string; mylist : handle; warn : boolean; tipo : integer; FUNCTION cambia(h:HANDLE):BOOLEAN; label 100; var r,g,b : longint; r1,g1,b1: longint; newclass: string; suffix : string; indice : integer; indice1 : integer; i : integer; BEGIN tipo := getType(h); {the script works only with 2d or 3d objects (650 and 651 selectors, see on-line manual appendix)} if (GetObjectVariableBoolean (h,651) or GetObjectVariableBoolean (h,650)) and (tipo<>11) and (tipo <> 15) then begin GetFillBack(h,r,g,b); GetPenFore(h,r1,g1,b1); RGBToColorIndex(r,g,b,indice); RGBToColorIndex(r1,g1,b1,indice); suffix := concat ('-', indice,'-',indice1); newclass := concat(prefix, suffix); {check if the class newclass already exists} i := 1; while (classlist(i) <> newclass) and (i < classnum) do begin i := i+1; end; if classlist(i) = newclass then {exit from while as soon as you find newclass exists} begin goto 100; sysbeep; end; if i = classnum then {exit from while at the end of classlist (without any newclass found)} begin nameclass(newclass); {attributes of selected object} GetFillBack(h,r,g,b); SetClFillBack(newclass, r,g,b); GetFillFore(h,r,g,b); SetClFillFore(newclass, r,g,b); GetPenBack(h,r,g,b); SetClPenBack(newclass, r,g,b); GetPenFore(h,r,g,b); SetClPenFore(newclass, r,g,b); if not GetObjectVariableBoolean (h,650) then {restricted to 2d obj, LW and LS gives error if the object is a 3D one} begin SetClLW(newclass,GetLW(h)); SetClLS(newclass,GetLS(h)); end; goto 100; end; 100:begin SetClass(h, newclass); {set class attributes} SetClUseGraphic(newclass, true); SetFillColorByClass(h); SetFPatByClass(h); SetLSByClass(h); SetLWByClass(h); SetMarkerByClass(h); SetPenColorByClass(h); end; end else if tipo = 15 then warn := true; END; {function} begin {main} warn := false; {ask prefix} prefix := StrDialog('Digit the class prefix',''); if prefix <> '' then begin ForEachObjectInList(cambia,2,1,myList); if warn then begin sysbeep; alrtDialog(concat('Some of selected objects is invalid. (type ',Num2Str(0,tipo),')')); end; end; end; run(col2class);[/code] Quote Link to comment
Recommended Posts
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.