Jump to content

Creating ChainDimension from Single Dimension


DomC

Recommended Posts

Hi there
I want to join single dimensions in one chain dimension. So far it works but I have an undo issue. If I undo the script my single dimensions are deleted and I also get an undo alert in the log file.

My simple test with two dimensions:
 

h1 = vs.FSActLayer()
h2 = vs.NextSObj(h1)

hnew = vs.CreateChainDimension(h1, h2)
	


My function to join n-Numbers of single dimensions

 

dimensions = []

def getObj(h):
	dimensions.append(h)
	
	
vs.ForEachObject(getObj, "(NOTINDLVP & NOTINREFDLVP & (SEL=TRUE))")	


h1 = dimensions[0]
for i in range(len(dimensions)-1):
	h1 = vs.CreateChainDimension(h1, dimensions[i+1])
	



The Scripts are working on selected objects for that test.


The Undo Alert I get:

"ALERT: Invalid undo primitive detected: Imminent crash is possible. Object 0x7ff725723440 is being inserted after it has been modified or deleted.","type":"INFO"}


Also really it is an undo issue because Unto after script deletes my dimensions. Have I to handle the undo events in a Vector Script?

Link to comment

Thanks for Feedback
 

2 hours ago, JBenghiat said:

That said, the Compose command will do what you want without a script. 

I will try with a DomMenuTextByName as a workaround, thanks
The complete Script has 800 lines (it reaches the limit of maximum size of a script), take a look here 🙂

An incredible powerful Auto-Dimension Script
 

 

59 minutes ago, Pat Stanford said:

for i in range(len(dimensions)-1):


The Second Script iterates through the length of dimensions. If I have the minimum of Objects (2) then length is 2
The loop starts with 0 and ends with 2-1 (1). If the loop would go till i == 1 i had an index of range with i+1. Different ways to do that with python.






 

Link to comment

The Function I use CreateChainDimension:
 

def create_chain_dim_vertical(intersection_points_sorted, x, offset, vp_scale): #standardly im text is left if there is no place between
	threshold_2_dimension, dimoff1, dimoff2, dimoff3 = create_globals(vp_scale , layer_scale , units)
	start = intersection_points_sorted[0]
	h1 = None; h_first = None
	prior_segment_length = 0
	prior_shifted_leftright = False; prior_shifted_up = False
	for i in range(len(intersection_points_sorted)-1):
		# startPt is always last endPt
		end = intersection_points_sorted[i + 1]
		segment_length = abs(end - start)
		if segment_length > epsilon:
			vs.LinearDim((x,start), (x,end), offset, 4, 769, True, 0.1)
			if data['b_debug_dim_color']: vs.SetPenFore(vs.LNewObj(), (65000,0,65000)); 
			color = (65000,0,65000)	
			if i > 0:
				h2 = vs.LNewObj()
				if not vs.GetObjectVariableBoolean(h2,30): #Text hatte kein Platz
					if i < len(intersection_points_sorted)-2: #not last dimension
						start_next = intersection_points_sorted[i+1] #=endPt
						end_next = intersection_points_sorted[i+2]
						next_segment_length =  abs(end_next - start_next)
						if prior_segment_length < threshold_2_dimension and next_segment_length > threshold_2_dimension:
							vs.SetObjectVariableBoolean(h2,29,False)#unlock Text position
							vs.SetObjectVariableReal(h2,44,-0.1)#text shift
							vs.SetObjectVariableBoolean(h2,29,True)#calculate dim text
							color = (65000,0,0); prior_shifted_up = False
						elif prior_segment_length < threshold_2_dimension and next_segment_length < threshold_2_dimension and prior_shifted_leftright == False:
							vs.SetObjectVariableBoolean(h2,29,False)#unlock Text position
							vs.SetObjectVariableBoolean(h2,30,True)#Text inside
							vs.SetObjectVariableReal(h2,44,-0)#text shift
							color = (0,30000,30000); prior_shifted_up = False
						elif prior_segment_length < threshold_2_dimension and next_segment_length < threshold_2_dimension and prior_shifted_leftright == True:
							vs.SetObjectVariableBoolean(h2,29,False)#unlock Text position
							vs.SetObjectVariableBoolean(h2,30,True)#Text inside
							if not prior_shifted_up:
								vs.SetObjectVariableReal(h2,43,offset_up); prior_shifted_up = True; color = (0,65000,0)
							vs.SetObjectVariableReal(h2,44,-0); color = (0,0,65000)
					else:
						vs.SetObjectVariableBoolean(h2,29,False)#unlock Text position
						vs.SetObjectVariableReal(h2,44,-0.1)#text shift
						vs.SetObjectVariableBoolean(h2,29,True)#calculate dim text
					prior_shifted_leftright = True	
				else:
					prior_shifted_leftright = False		
				#prior_segment_unshifted = vs.GetObjectVariableBoolean(h2,30) #debug
				if data['b_debug_dim_color']: vs.SetPenFore(h2, color)
				vs.ResetObject(h2); #vs.SetPenFore(h2, (65000,0,0))
				vs.ResetObject(h1)
				h1 = vs.CreateChainDimension(h1, h2)
				
			else: #first dimension > move to left
				h1 = vs.LNewObj()#;vs.SetPenFore(h1, (65000,0,0))
				if not vs.GetObjectVariableBoolean(h1,30): #Text hatte keinen Platz
					vs.SetObjectVariableBoolean(h1,29,False)#unlock Text position
				vs.SetObjectVariableReal(h1,44,0); 
				if data['b_debug_dim_color']: vs.SetPenFore(h1, (30000,0,30000))
					
			#vs.AlrtDialog(str(h1))
		prior_segment_length = abs(end - start)
		start = end
	chain_dims.append(h1)

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...