Urgent Script Help Needed to Type Text

Urgent Script Help Needed to Type Text

Byteman
Collaborator Collaborator
964 Views
8 Replies
Message 1 of 9

Urgent Script Help Needed to Type Text

Byteman
Collaborator
Collaborator

Hi,

I have an Excel Sheet with names of 650 persons in the Names Column, each in a separate line. From B2 to B651.

 

I need to create separate text objects from each line containing Name Surname (May be a third name on some names). May any of you be kind enough to write such a script if possible?

 

Some parameters need to be set on each text object, like Interpolation to be set to 2 to keep it low poly, and a font setting would be good, but I think those settings are kept, once a text object present in scene has those settings.

 

And creation of each object side by side with a certain distance parameter will be appreciated. I need to place each name on an array of 650 objects placed at equal distances. Otherwise I'll need to align one by one.

 

Thank you

0 Likes
Accepted solutions (1)
965 Views
8 Replies
Replies (8)
Message 2 of 9

denisT.MaxDoctor
Advisor
Advisor

can the data be in the CSV file format?

I really don't want to mess with python just to read data

0 Likes
Message 3 of 9

Byteman
Collaborator
Collaborator

I've just checked Dennis. It exports to CSV. The end result is something like a text file with, each name+surname on one line. No commas after names, but if that is necessary I think I can figure it out.

0 Likes
Message 4 of 9

denisT.MaxDoctor
Advisor
Advisor

I know what CSV is... so it's much easier now.

Try to explain what you need a little more clearly...maybe some pictures will help.

Message 5 of 9

Byteman
Collaborator
Collaborator

You know what? This is still the same project you've helped me with organizing some bricks back in February or March this year. For some reason thay have postponed the show several times I hope it's going to be finalized in a few days.
This scene I'm working on is below.


https://forums.autodesk.com/t5/3ds-max-forum/assigning-material-id-s-automatically/m-p/10993794
I tried to solve this as maps 5 moths ago, but it had its shortcomings and after the project is postponed I stopped  working on it, but it is harder to create 650 maps. (The number of names was 250 then) Tried unwrapping, too but couldn't succeed in that either. 

 

I want to place each name text obj. on the side of one carabina. If the names can be converted to separate text obj.s and each object can be created as an array (with the same distance from each other) I can simply rotate, extrude and attach. 

My System Units  Setup is centimeters. Array offset distance should be 11,927cms which means each copy's pivot should be 11,927 cm's from the previous one. Actually the next chain placement center is half of it but every other chain is rotated 90 deg. about its longitudinal axis so I'll do this in two steps or I may change the distance from script and rotate every other name.

 

Such a meaningless project to work on. Who's going to read all those names on such small objects but the client wants. 

0 Likes
Message 6 of 9

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

 

try(destroydialog TextBeltRol) catch()
rollout TextBeltRol "Text Belt" width:191
(
	fn isTextObject obj = iskindof obj.baseobject Text
	
	local text_template = text_template
	local recent_file = unsupplied
	local recent_texts
	
	pickbutton pick_template_bt "< Pick Text Template Node >" width:172 autodisplay:on align:#left offset:[-4,2] filter:isTextObject \
		tooltip:"Pick a node to be used as a template"

	spinner spacing_sp "Spacing: " type:#worldunits range:[0,1e6,10] fieldwidth:58 align:#right offset:[4,6]
	spinner roll_sp "Roll: " type:#float range:[-360,360,90] fieldwidth:58 align:#right offset:[4,0]	
	
	radiobuttons target_name_rb "Make Name From:" labels:#("Template", "File") default:2 columns:1 align:#left offset:[9,4] offsets:#([92,-16],[92,-16]) 

	checkbutton create_bt "Create From File..." highlightcolor:orange width:104 align:#left offset:[-4,6] across:2 \
		tooltip:"Pick a File..."
	button repeat_bt "Repeat" width:66 align:#right offset:[4,6] \
		tooltip:"Repeat Last File\n +ALT\t- Delete previuos nodes"
	
	progressbar progress_pb color:orange width:172 height:8 align:#center offset:[0,-2]
	
	label info_lb "info..." width:172 align:#left offset:[-4,4]

	fn loadTextBeltData file: =
	(
		local texts
		if file == unsupplied do file = getOpenFileName filename:recent_file caption:"Load Text List File" types:"CSV File(*.csv)|*.csv"
		if iskindof file String and doesfileexist file and (ss = openfile file) != undefined do
		(
			recent_file = file
			texts = #()
			while not eof ss do
			(
				str = filterstring (readline ss) ","
				if (str.count >= 2) do
				(
					append texts str[2]
				)
			)
			--if texts.count == 0 do texts = undefined
			
			flush ss
			close ss
		)
		texts
	)
	
	local recent_nodes 
	
	fn make_valid_text text = 
	(
		text = trimleft text " \t"
		text = trimright text " "
	)
	fn make_valid_name text = 
	(
		text = substitutestring text " " "_"
	)
	
	on pick_template_bt picked obj do
	(
		if isvalidnode obj do text_template = obj
	)
	on pick_template_bt rightclick do
	(
		if isTextObject (node = selection[1]) do
		(
			pick_template_bt.object = text_template = node
		)
	)

	fn createTextBelt filename: = if isvalidnode (node = text_template) do
	(
		texts = loadTextBeltData file:filename
		if texts.count do
		(
			sp = spacing_sp.value
			rt = roll_sp.value
			tm = node.transform 
			base = node.name + "_"
			col = node.wirecolor * 0.75
			
			info_lb.text = "info..."
			progress_pb.value = 0
			factor = 100.0/texts.count
			
			-- we skip first...
			
			recent_nodes = for k = 2 to texts.count while not keyboard.escpressed collect
			(
				text = make_valid_text texts[k]
				
				name = if target_name_rb.state == 1 then uniquename base else (make_valid_name text)
				t = copy node name:name parent:node wirecolor:col
				t.baseobject.text = text
				
				t.transform = translate (rotateX (copy tm) ((k-2) * rt)) [(k-2) * sp, 0, 0] 
				
				progress_pb.value = (k + 1) * factor
					
				t
			)
			
			info_lb.text = "create nodes: " + recent_nodes.count as string
			
			recent_texts = texts
			recent_nodes
		)
		completeredraw()
	)
	
	on create_bt changed state do undo "Create Text Belt" on
	(
		createTextBelt()
		create_bt.state = off
	)
	on repeat_bt pressed do undo "Create Text Belt" on
	(
		if keyboard.altpressed do try (delete recent_nodes) catch()
		
		createTextBelt filename:recent_file
		create_bt.state = off
	)

	on TextBeltRol open do
	(
		if isvalidnode text_template do pick_template_bt.object = pick_template_bt
	)
)
createdialog TextBeltRol escapeEnable:true

-- TextBeltRol.recent_texts

/* CSV file: *******************************************

Rank, Company, Country, Annual Steel Production (million tons)
1, ArcelorMittal, Luxembourg, 96.5
2, China Baowu Group, China, 67.5
3, Nippon Steel Corporation, Japan, 49.3
4, HBIS Group, China, 46.9
5, POSCO, South Korea, 42.9
6, Shagang Group, China, 40.7
7, Ansteel Group, China, 37.4
8, JFE Steel Corporation, Japan, 29.2
9, Jianlong Group, China, 27.9
10, Shougang Group, China, 27.4

*/

 

 

1. make a CSV file where the first row is the column headings as usual (we skip it).

2. create a template text spline node that will be used for all created text objects from the file as instance

3. set the spinners to the required values

4. pick the template node

5. create text nodes using the "Create From File..." button

6. use the Undo and "Repeat" buttons if we need to redo the creation with different settings using the last used CSV file.

 

 

0 Likes
Message 7 of 9

denisT.MaxDoctor
Advisor
Advisor

The script creates text nodes starting at the template node in the x direction and with turn around the x-axis.

 

Be free to change rules and default settings. You can create the template node once and merge it from a file. Technically it is possible to use XRef system for the template and make node references instead of copies.

0 Likes
Message 8 of 9

Byteman
Collaborator
Collaborator

Dennis, I can't express by words how much I appreciate your help. 😍 This is exactly what I need and it will help me save a lot of time, even in some future projects.

 

Template feature works like charm. Settings like interpolation or alignment can be set for all objects and if you have implemented this Undo feature in the script, it requires additional appreciation. 🤗

 

It worked seamlessly. There is one thing though which did not cause any trouble:

Byteman_1-1661334694935.png

 

 

First name is somehow omitted.

 

I've written the first name in the list as template text, which is "Alara Reyhan".

The second name "Ali Gumus" was created right on the template text as the first name.

Last carabina was empty.

 

I've just selected all text objects except the template text and moved them to the right, one Spacing distance.

 

It is perfectly working.

0 Likes
Message 9 of 9

denisT.MaxDoctor
Advisor
Advisor

@Byteman wrote:

 

Template feature works like charm. Settings like interpolation or alignment can be set for all objects and if you have implemented this Undo feature in the script, it requires additional appreciation. 🤗

 

First name is somehow omitted.

 

I've written the first name in the list as template text, which is "Alara Reyhan".

The second name "Ali Gumus" was created right on the template text as the first name.

Last carabina was empty.

 


~settings like interpolation or alignment can be set for all objects

You must do this in the template node. All created nodes use all settings (except the text) from the template node.

 

~if you have implemented this Undo feature in the script...

It has to be undoable

 

~first name is somehow omitted

CSV file usually contains the column headings in the first line to define data format. So, I skip the first line. You can add a "technical" first line to every file or fix the code. 

0 Likes