Jump to content

Small simple script


Recommended Posts

I'm an enthusiastic VW user for over a decade. Recently I noticed I have to do many things often and as such I'm starting to look at automation of tasks. I'm considering to learn Python as I would like to automate several things, but it will take time.

 

I like to draw shadow on facades to make the more vibrant.

 

At the moment I'm willing to pay an experienced user some money for a small script related to the shadow. What I basically need is;

  • Take on or more squares;
  • Take the top line and offset 50mm down;
  • Take the right line and offset 50mm to the left;
  • Create new rectangles from that set of lines;
  • "Add surface" those two new rectangles;
  • Fill color black, oppacity 40%.

 

Is there someone in this forum willing to write this for me or can you point me to a place where I can find someone? Willing to pay.  I guess I'm looking for the code in Python.

Link to comment

Hello,

 

assuming all the rectangles are alligned to the x and y axis the following script should do the trick.

 

# FUNCTIONS
def selection_on_active_layer_to_handle():
	handles = []
	def callback_selection_on_active_layer_to_handle(handle):
		handles.append(handle)
	vs.ForEachObject(callback_selection_on_active_layer_to_handle, "(NOTINDLVP & NOTINREFDLVP & ((L='" + vs.GetLName(vs.ActLayer()) + "') & (VSEL=TRUE)))")
	return(handles)


# SCRIPT
selection = selection_on_active_layer_to_handle()

for item in selection:
	if vs.GetTypeN(item) == 3:
		blank = vs.CreateDuplicateObject(item, vs.Handle(0))
		tool = vs.CreateDuplicateObject(item, vs.Handle(0))
		
		vs.HMove(tool, -0.5, -0.5) # change "-0.5, -0.5" to the desired offset, depending on the units you use in your drawings
		
		vs.SetFPat(blank, 1)
		vs.SetFillBack(blank, (0, 0, 0))

		vs.SetOpacityN(blank, 40, 40)
		
		vs.ClipSurfaceN(blank, tool)
		
		vs.DelObject(blank)
		vs.DelObject(tool)
		
	vs.SetDSelect(item)

 

You will have to change some values in the script because i dont know which units you use. I kept this script as simple as possible so i dont take care of different document units via the script.

I think you maybe want to modify the script even further, because from your post it was unclear:

- If the original rectangles should be deleted by the script

- If the Shadow has an outline

- If so, which opacity

- etc.

 

Here is how this script works:

- Read in all the selected objects on the active layer and "save" them in a list

- Go through all the objects in this list

- If the object is a rectangle

- Create two duplicates of the rectangle

- Move one of them by the amount you specified the offset to be (width and height of the shadow)

- Set the color and opacity of the other duplicated rectangle to the right values (black and 40%)

- Clip the moved rectangle from the colored rectangle

- Deselect the original item

 

 

Regards,

Letti

  • Like 4
Link to comment

Ah yes, I misread the directions of the offsets. The drop shadow attribute would only work if the façade were a single polygon with holes. For example, use the inner boundary mode of the polygon tool to create the shape, then apply the drop shadow. So possible, but a bit cumbersome. 

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...