Jump to content
Sign in to follow this  
DomC

Try to change Dimension values via Script

Recommended Posts

Hi all

My current issue is a Python script, which takes a grouped 2D drawing and reshape it. This group contains rectangles, which can be used as reshape regions. Both (group and reshape zones) get handled via user record format or symbol definition.

Because there is unfortunately no corresponding script command like the reshap tool it needs to handle all objects, check their type and reshape them all with their own possibilities. So far this works amazing good and this will be a powerful gadget to create standard-drawings of devices. I will post this, as soon it's time for it ;)

The Question:

Someone knows a trick, to handle dimension value (length)? I tried to change records, changing custom object path, etc. No success! So my workaround is, to use just associated dimensions.

And now the next hurdle is, to get those dimensions to follow their associated points while the objects are reshaped or moved. So far the constraints are still intact. I tried reset, redraw and chaning some dimension values (note text, dim standard etc.)

So the workaround seems to be to move alle objects at the end again (0.1 to the right, -0.1 to the left). This solve the problem.

Someone knows nicer technique to do this?

Some lines of the python code:

def reshape(): # Modify all Points inside the reshape rect. Check all Object Types and modify them in their specific way.
	offset=[offsetx,offsety]
	blistbbox,blistpoints=ifinrect()
	types,objs=getobj()
	rect=getrect()
	points=getbbox()
	n=0
	#vs.AlrtDialog(str(points))
	count2_63=[]
	count3=[]

	for x in objs:
		if blistbbox[n]==False:			
			if types[n] == 5 or 21: #polygon, polylines	
				#pass			
				num=vs.GetVertNum(objs[n])
				for y in range(num):
					p = vs.GetPolyPt(objs[n], y+1)
					b=vs.PtInRect(p, rect[0],rect[1])

					if b==True:
						vs.SetPolyPt(objs[n], y+1, p[0]+offsetx, p[1]+offsety,)

			if 	types[n] == 2 or 63: #Line Objects (Walls, Dim, Lines, etc.)
				p1=vs.GetSegPt1(objs[n])
				p2=vs.GetSegPt2(objs[n])
				b1=vs.PtInRect(p1,rect[0],rect[1])
				b2=vs.PtInRect(p2,rect[0],rect[1])
				newp1=p1[0]+offsetx,p1[1]+offsety

				newp2=p2[0]+offsetx,p2[1]+offsety
				if b1==True:
					vs.SetSegPt1(objs[n], newp1)
				if b2==True:
					vs.SetSegPt2(objs[n], newp2)

			if types[n] ==3:  

				bleft=vs.PtInRect(points[n][0],rect[0],rect[1]) #should be made with blistpoints, but for the moment ... this works 
				bright=vs.PtInRect(points[n][1],rect[0],rect[1])

				if bleft==True:
					vs.SetBBox(objs[n], points[n][0][0]+offsetx, points[n][0][1]+offsety, points[n][1][0],points[n][1][1])
				if bright==True:
					vs.SetBBox(objs[n], points[n][0][0], points[n][0][1], points[n][1][0]+offsetx,points[n][1][1]+offsety)


		if blistbbox[n]==True: #All containers or objects, which are complete in the reshape zone.
			vs.HMove(objs[n], offsetx,offsety)

		n=n+1
	return()


def resetdim(): #collects all objects in group g
	h = vs.FInGroup(g)		
	while h != vs.Handle(0):
		type=vs.GetTypeN(h)
		if type== 63:
			vs.ResetObject(h)
			#vs.AssociateLinearDimension(h,True)
			#vs.SetDimNote(h,'DLO')
		h = vs.NextObj(h)
	return()

def resetall(): #collects all objects in group g
	h = vs.FInGroup(g)		
	while h != vs.Handle(0):
		vs.ResetObject(h)
		h = vs.NextObj(h)
	return()

def moveall(): #try workaround to reshape associated dimensions
	h = vs.FInGroup(g)		
	while h != vs.Handle(0):
		vs.HMove(h, 0.1,0.1)
		vs.HMove(h,-0.1,-0.1)
		h = vs.NextObj(h)
	return()


reshape()
moveall()	
resetall()	
resetdim()

And a clip of a simple test object, attached to this post.

Share this post


Link to post

If anyone is interested. I got it :-)

Object Value 13 and 14. Example Code (Activate a Dim, if you want to test or you will crash):

dim=vs.FSActLayer()
p1=(2,3,0)
p2=(7,3,0)
vs.SetObjectVariablePoint(dim,13,p1)
vs.SetObjectVariablePoint(dim,14,p2)
vs.ResetObject(dim)

I found nothing in the VW appendix. I just looped all possible commands, settings and variables and searched the right kind of data.

Share this post


Link to post

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.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...