stp格式文件导入3ds Max MaxScript批处理工具

news/2024/11/15 4:35:03/

〇、说明
0.除自定义脚本,其余示例摘自3DS MAX 2017 Help
1.将乱码部分统一命名,调整规则如下;
a.mesh节点:如果mesh乱码,其父物体命名正确,则将其命名为与父物体同名;
b.对于所有节点,如果名称中含有"|:|",则截取第一个"|“前的字符作为名称,否则,删除名称中的非法字符,作为名称(第一个”|“前的字符相同的mesh多为同一对象,第二个”|“的猜测为类似索引值的标记),如果首字符为”_",则添加"Object"前缀(主要因为此种情况下经删除非法字符后保留的字符较少);
2.将指定文件夹下所有stp逐个导入到3ds Max并分别在各自路径下导出为fbx;
3.调整每个对象的缩放值(1,1,1)和轴心点(位于物体的中心);
4.删除同一虚拟节点下重复的Mesh(尚存问题,已弃用);
a.如果两个mesh中的一个是另一个的冗余部分,则删除顶点较少的mesh对象;
b.如果两个mesh是不同的对象,则保留;
c.以上判断通过两个mesh的center的点积进行判断的(尚存问题);
一、MaxScript
1.StpModelCovertToFbxTool

global validChar="_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"fn filteringInvalidChar instring =-- beginning of function definition
( local outstring-- declare variables as local
-- create an unique copy of the string referenced by instring,
-- and store reference to unique copy in outstring
-- set variables to literalsresult =""outstring=copy instring-- increment from 1 to number of character in stringfor i=1 to outstring.count do(
-- see if the single character at index i in outstring
-- is present instring lower
-- If so, j equals position in string validChar.
-- If not, j equals undefineda=findstring validChar outstring[i]if a!=undefined thenresult+=outstring[i]else result-- value will be returned as function result)result
)fn getFilesRecursive root pattern =
(dir_array = GetDirectories (root+"/*")for d in dir_array dojoin dir_array (GetDirectories (d+"/*"))my_files = #()for f in dir_array dojoin my_files (getFiles (f + pattern))my_files
)fn correctGeometryName =(for obj in geometry do(splitName=filterString  obj.name "|"if splitName.count>1 thenobj.name=splitName[1]else(for i=1 to obj.name.count do(		if obj.name[i]!=undefined do(		b=findstring validChar obj.name[i]if b==undefined doobj.name=obj.parent.name)		)	))
)fn correctNodeName =(i=0for obj in objects do(rightname=filteringInvalidChar obj.name as stringif rightname.count>1 thenobj.name=rightnameelse (obj.name="Target"+i as stringi+=1)if obj.name[1]=="_" doobj.name="Object"+obj.name)
)fn resetModel=(for obj in objects do(CenterPivot objResetScale  objResetTransform obj) 
)
#尚存问题
fn deleteRepeatedModel=(for obj in geometry do(if obj.parent.children.count>=2 do(if (dot obj.parent.children[1].center obj.parent.children[2].center<30)  do(try(if obj.parent.children[1].verts.count  <obj.parent.children[2].verts.count thendelete obj.parent.children[1]else delete obj.parent.children[2])catch ())))
)stpModelPath="E:\Unity Arts Assets\3ds Max\Schneider Pan Gu"
--stp原始模型路径dir_array = getFilesRecursive stpModelPath "*stp"print dir_array.count as string
for	i=1 to dir_array.count do(print dir_array[i]
)for d in dir_array do(	for	f in getfiles d do(loadmaxfile fcorrectGeometryName()correctNodeName()resetModel()#deleteRepeatedModel()fname=(filterString(pathConfig.stripPathToLeaf d) ".")[1]+".fbx"exportfile (pathConfig.removePathLeaf d+"\\"+fname) #noprompt selectedonly:false using:fbxexp)
)

2.WriteAllStpMoldelPathToTxt

fn format_txt filepath filetext =
(if doesFileExist filepath == true then(fin = openfile filepath mode:"r+"seek fin #eoftxt = filetext + "\n"format txt to:finclose fin)else(newfile = createFile filepathclose newfileformat_txt filepath filetext)
)stpModelPath="E:\3ds Max\Stp Models"
--stp原始模型路径txtPath="E:\Unity Arts Assets\3ds Max\Schneider Pan Gu\StpList.txt"dir_array = getFilesRecursive stpModelPath "*.stp"for	i=1 to dir_array.count do(format_txt txtPath dir_array[i] as string
)

3.findString

<integer>findString<string> <search_string>
Returns the index of search_string in string or undefined if not found.

EXAMPLE

findString "Thanks for all the fish!" "all" -- returns 12 

4.The following script shows the use of various literals, constructors, properties, operators, and methods of the String class.
EXAMPLE

-- strings test bed
fn uppercase instring =-- beginning of function definition
( local upper, lower, outstring-- declare variables as local
upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"-- set variables to literals
lower="abcdefghijklmnopqrstuvwxyz"-- create an unique copy of the string referenced by instring,
-- and store reference to unique copy in outstring
outstring=copy instring-- increment from 1 to number of character in string
for i=1 to outstring.count do-- see if the single character at index i in outstring
-- is present instring lower
-- If so, j equals position in string lower.
-- If not, j equals undefined
( j=findString lower outstring[i]-- if character was found in lower,
-- replace with corresponding character in upper:
if (j != undefined) do outstring[i]=upper[j]
)
outstring-- value will be returned as function result
)-- end of fn uppercases1="AbCdEfGh"-- set variable to literal
s2=uppercase s1-- call function uppercase, passing s1 as parameter
if s1 == s2 do print "strings s2 and s3 are the same"-- compare strings
if s1 != s2 do print "strings s1 and s2 are different"theObject="sphere"-- set variable to literal
theRadius= (random 10. 100.) as string-- convert number to string
-- concatenate strings and execute string
myObject=execute (theObject +" radius:"+ theRadius)

OUTPUT:

uppercase()-- result to function definition
"AbCdEfGh"-- result of line 24
"ABCDEFGH"-- result of line 25
undefined-- result of line 26 - stringsnot equal,
-- and no else expression in if expression
"strings s1 and s2 are different"-- output from line 27
"strings s1 and s2 are different"-- result of line 27
"sphere"-- result of line 29
"75.4091"-- result of line 30
$Sphere:Sphere001 @ [0.000000,0.000000,0.000000]-- result of line 32. Execute function
-- created a sphere object 

5.getFiles

getFiles <wild_card_filename_string> 	 

Returns an array of file names that match the given wild-card path name.

FOR EXAMPLE,

The following code gets an array of all the .max scene files in c:\foo and then loops over the array, opening each file and printing the objects in each:

files = getFiles "c:\\foo\\*.max"
for f in files do (loadMAXFile f; print objects)

getFiles() can also be used to determine if a file or file pattern exists.

FOR EXAMPLE

the following function will return true if the specified file name or pattern exists:

fn existFile fname = (getfiles fname).count != 0

See also doesFileExist() which checks for a single file only and does not supportwildcardpatterns.

6.getDirectories <wild_card_directory_name_string>

Returns an array of directory paths that match the given wild-card directory path name.

SCRIPT

fn getFilesRecursive root pattern =
(
dir_array = GetDirectories (root+"/*")
for d in dir_array dojoin dir_array (GetDirectories (d+"/*"))
my_files = #()
for f in dir_array dojoin my_files (getFiles (f + pattern))
my_files
)
--get all .ms files from the folder c:/temp
--and all its subfolders:
getFilesRecursive "c:/temp" "*.ms"

7.filterString

<array of strings>filterString <string> <token_string> [splitEmptyTokens:<boolean>]

Parses string based on token_string and returns an array of strings. The filterString splits the input string into substrings based on the characters given in token_string , and returns each substring as a member of the array. The token_string is simply a list of ‘splitter characters’ (when the string is scanned, any occurrence of any of the tokens is regarded as the start of a substring). This function is useful for file import/export scripts or for any type of manual parsing.

FOR EXAMPLE

filterString "MAX Script, is-dead-funky" ", -"

WOULD RETURN

#("MAX","Script","is","dead","funky")

If splitEmptyTokens is false or not specified, sequential tokens are handled as a single token and tokens at the beginning or end of the string are ignored. If splitEmptyTokens is true , each token found will result in string element in the output, with the string element in the cases ignored above being empty strings

8.pathConfig.removePathLeaf

pathConfig.removePathLeaf <path> 

Removes a leaf from the given path.

FOR EXAMPLE,

pathConfig.removePathLeaf "c:\\temp\\test"
"c:\temp"

pathConfig.stripPathToLeaf

9.pathConfig.stripPathToLeaf <path_or_filename> 

Returns the last sub-directory name from the given path. If the path is a full file name, returns the file name. Equivalent to filename from path.

EXAMPLES:

pathConfig.stripPathToLeaf "C:\\temp\\test"
"test"
pathConfig.stripPathToLeaf "C:\\temp\\test\\"
""
pathConfig.stripPathToLeaf "C:\\temp\\test\\somefile.tga"
"somefile.tga"
--COMPARE:
filenamefrompath "C:\\temp\\test"
"test"
filenamefrompath "C:\\temp\\test\\"
""
filenamefrompath "C:\\temp\\test\\somefile.tga"
"somefile.tga"

10.CenterPivot

CenterPivot <node>-- mapped method

Same as Hierarchy/Pivot/Affect Pivot Only - Center to Object.

11.ResetScale

ResetScale <node>-- mapped method 

Same as Hierarchy/Pivot/Reset Scale.
Vector Dot Product

12.dot

dot <point3> <point3>

Returns the vector dot product.

The geometric interpretation of the dot product is the length of the projection of the first vector onto the unit vector of the second vector. Obviously, when the two vectors are perpendicular, the dot product is 0.0.

The dot product is commutative, which means that dot X Y == dot Y X.

The dot product is associative, which means that dot (rX) Y == r(dot X Y).

The dot product is distributive, which means that dot X (Y+Z) == (dot X Y) + (dot X Z).

Because the dot product of two normal vectors is the cosine of the angle between them, the dot product can be used conveniently to calculate the angle between two vectors:

FOR EXAMPLE

fn GetVectorsAngle v1 v2 =
(theAngle = acos(dot (normalize v1) (normalize v2))
)GetVectorsAngle [10,0,0] [10,20,0]
63.435

13.Try Expression
Try Expression


http://www.ppmy.cn/news/692783.html

相关文章

creo打不开stp文件_proe(creo)转为STP格式保证颜色不变方法

proe转为STP等其它格式时如何保证颜色一致保持不变的方法 proe转为STP等其它格式时保证颜色一致的方法是&#xff1a; 工具----选项下将 本帖隐藏的内容 step_export_format 值设为&#xff1a;ap214_cd或ap203_is_ext或ap214_dis或ap214_is ap203_is(3D 模式中的缺省值)、ap21…

creo打不开stp文件_Creo怎么打开stp格式的文件?

Creo可以直接打开stp文件 点击打开文件&#xff0c;在类型列表选择“STEP”或者“所有文件”&#xff0c;即可看到stp后缀的文件&#xff0c;双击或者点击“导入”即可。打开stp文件的对话框选择 导入时最好勾选模板&#xff0c;这样新打开stp文件就会含有你的模板信息&#xf…

STP技术基础

STP出现的背景&#xff1a; 物理环路是必要的&#xff0c;为什么这样说呢&#xff1f;因为为了保证一个冗余&#xff0c;当最优的链路断开后&#xff0c;还可以通过另外的链路到达对方&#xff0c;但是物理环路会导致二层的环路&#xff0c;这样就会发生如下的情况&#xff1a…

STP/RSTP/MSTP帧格式、报文格式及字段说明

STP&#xff08;Spanning Tree Protocol&#xff0c;生成树协议&#xff09;是一种二层&#xff08;数据链路层&#xff09;管理协议&#xff0c;它通过有选择性地阻塞网络冗余链路来达到消除网络二层环路的目的&#xff0c;同时具备链路的备份功能。最初被广泛应用的是IEEE 80…

STP报文格式与端口状态

1.STP交换机通过交换STP协议帧来建立和维护STP树&#xff0c;并在网络的物理拓扑发生变化时重新建立STP树。 2.STP协议帧由STP交换机产生&#xff0c;发送、接收和处理。STP协议帧是一种组播帧&#xff0c;组播地址是01-80-c2-00-00-00。 3.STP协议帧采用IEEE 802.3封装格式&…

大数据Doris(五十四):BACKUP数据备份原理和语法

文章目录 BACKUP数据备份原理和语法 一、BACKUP数据备份原理 1、快照及快照上传 2、元数据准备及上传 二、BACKUP数据备份语法 BACKUP数据备份原理和语法 通过Doris数据导出的各种方式我们可以将Doris中的数据进行备份&#xff0c;除了export方式之外&#xff0c;Doris 还…

python的函数定义要在调用之前吗?

在Python中&#xff0c;函数必须在调用之前定义。如果你试图在定义一个函数之前调用它&#xff0c;Python会抛出一个NameError&#xff0c;告诉你这个函数尚未定义。 例如&#xff1a; # 错误的顺序 my_function() # 这会引发 NameError&#xff0c;因为 my_function 还未定…

装饰器设计模式应⽤-JDK源码⾥⾯的Stream IO流

装饰器设计模式在JDK源码⾥⾯应⽤场景 抽象组件&#xff08;Component&#xff09;&#xff1a;InputStream 定义装饰⽅法的规范被装饰者&#xff08;ConcreteComponent) : FileInputStream、ByteArrayInputStream Component的具体实现&#xff0c;也就是我们要装饰的具体对…