ScriptSpot

Forum topic · General Scripting

Merge xrefs, change color geometry and convert back to xref

By remykonings · 2021-03-11

Description

Hi,

I'm looking to merge some xrefs by their selected parent dummies. Merge them into the scene, change their wireframe color and convert them back into an xref at the same file-path with the same name and attached to the same parent dummy as before they got merged, to eventually add them back into the scene again.

Is this possible? looking at some of the syntaxes I believe so but not sure how to make it work.

Hope you have a solution for me :)

Kind regards,
Remy

Comments (2)

shift click to save wirecolor

id_ivan · 2021-03-20

Shift click otherwise this only change xref wirecolor in current session.

(
	try (destroyDIalog ::testDialog)catch()
	rollout testDialog "xref wirecolor changer"
	(
		colorpicker theColor "Wireframe color:" color:[0,0,255] modal:false
		button btn_Next "Change wirecolor" tooltip:"Change xref color in this session.\nShiftClick: Save the newcolor to xref file" width:150 height:40 
		on btn_Next pressed do
		(
			toColor =theColor.color -- destination color
			objs = for o in objects collect o
			obj=if selection.count != 1 then (messagebox "Please select xref parent" beep:false;return false) else selection[1]
			xrC = xrefs.getXRefFileCount()
			for i=1 to xrC do (
				xrf = xrefs.getXRefFile i
				if xrf.parent == obj do (
					if keyboard.shiftPressed then (
						fname =xrf.filename
						xrf.parent=undefined
						merge xrf
						max select none
						select (for o in objects where (findItem objs o) == 0 collect (o.wirecolor=toColor; o))
						saveNodes selection fname
						delete selection
						newXr = xrefs.addNewXRefFile fname
						newXr.parent=obj
						select obj
					) else (
						xrObjs = xrf.tree.children
						for o in xrObjs do ( o.wirecolor = toColor )
					)
				)
			)
		)
	)
	createDialog testDialog
)

*

remykonings · 2021-03-23

Thank you sir