Jump to content

Assign object to a different Layer


Recommended Posts

I am trying to automate importing a number of DXF files, I got this working in batch mode based on help here. 

 

isBatch = True
RoadLQ16 = vs.ImportDXFDWGFile('/Users/some.guy/Desktop/Script/RoadLQ16.dxf', isBatch)

 

This works fine but I want to group the imports into specific layers. I have tried using vs.SetParent and VS:CreateDuplicateObject but I am misunderstanding something about handles (I think) 

These attempts don't work

isBatch = True
RoadLQ16 = vs.ImportDXFDWGFile('/Users/some.guy/Desktop/Script/RoadLQ16.dxf', isBatch)
vLayer_Destination_Handle = vs.GetLayerByName('Noise')
vs.CreateDuplicateObject('RoadLQ16', vLayer_Destination_Handle)

 

isBatch = True
RoadLQ16 = vs.ImportDXFDWGFile('/Users/some.guy/Desktop/Script/RoadLQ16.dxf', isBatch)
vLayer_Destination_Handle = vs.GetLayerByName('Noise')
vs.SetParent('RoadLQ16', vLayer_Destination_Handle)

 

Link to comment

I think the issue is that the vs.ImportDXFDWGFile function returns and integer not the objects imported? therefore the HANDLE isn't any use?

 

I have found the code below but I can't make much sense of it

 

# use		:	assigns a new layer to objects selected by criteria

def object_layer_assign_criteria(vSelection_Criteria, vLayer_Destination_Name):
	
	vLayer_Destination_Handle = vs.GetLayerByName(vLayer_Destination_Name)
	if vLayer_Destination_Handle == None:
		vLayer_Actual_Handle = vs.ActLayer()
		vLayer_Actual_Name = vs.GetLName(vLayer_Actual_Handle)
		vs.Layer(vLayer_Destination_Name)
		vLayer_Destination_Handle = vs.ActLayer()
		vs.Layer(vLayer_Actual_Name)
	
	def object_layer_assign_iterator(vObject_Handle):
		vs.SetParent(vObject_Handle, vLayer_Destination_Handle)
	
	vs.ForEachObject(object_layer_assign_iterator, vSelection_Criteria)

 

Link to comment

1. never ever import into a file that already has data you care about. It is bad juju and at some point it will corrupt and you will regret it.

 

2. If you are importing into a blank file you can realitlvey easily write a script that will walk every object in the file and move them to the layer you want them on.

 

3. Make sure the layer you imported into is at the top of the stacking list and then start with the last object in the file and work backwards. That way you don't have to worry about reprocessing objects if they happen to get moved lower in the stacking order.

 

4. SetParent is the right call unless you really want to make a duplicate.

 

My Python is not good enough to be able to hack this while in the airport, so the following is a strange Python/Vectorscript pseudo language that will not run.

 

MyObject = vs.LastObject

While MyObject <> Nil DO

Begin

   Check what MyObject is and determine what layer it should be moved to.

   vs.SetParent(MyObject, ItsLayer)

   MyObject = vs.PreviousObject(MyObject)

End

Link to comment

The code below uses "ForEachObjectInLayer" and seems to work.

I am a bit fuzzy on how to correctly pass the HANDLE from ForEachObject to SetParent

 

 

isBatch = True
MyLayer = vs.GetLayerByName('LiDARContours')
def sendtoconstraints(h):
	vs.SetParent(h, MyLayer)
Contours1m = vs.ImportDXFDWGFile('/LiDARScript/1m3dContours.dxf', isBatch)
vs.ForEachObjectInLayer(sendtoconstraints, 0, 0, 0 )
Contours50cm = vs.ImportDXFDWGFile('/LiDARScript/50cm3dContours.dxf', isBatch)
vs.ForEachObjectInLayer(sendtoconstraints, 0, 0, 0 )
MyLayer = vs.GetLayerByName('Noise')
RoadLQ16 = vs.ImportDXFDWGFile('/LiDARScript/RoadLQ16.dxf', isBatch);
vs.ForEachObjectInLayer(sendtoconstraints, 0, 0, 0 )
RailLQ16 = vs.ImportDXFDWGFile('/LiDARScript/RailLQ16.dxf', isBatch);
vs.ForEachObjectInLayer(sendtoconstraints, 0, 0, 0 )

 

Link to comment

ForEachObject automatically passes the handle for each object specified by the criteria to the SendtoConstraints procedure. The handle you define in the Def line is the handle passed by ForEachObject. So you are doing it exactly right.

 

Nice job of translating my pseudo code!

Link to comment

I tried to translate your code and I think I got it to run but it crashed, I think it was stuck in a loop looking for the previous object or something. 

vs.ForEachObjectInLayer seems much better than  While MyObject <> Nil DO for me. 

 

Defining the new procedure and passing handles around makes a lot more sense now. 

 

 

  • Like 1
Link to comment

Lots of ways to handle scripts.

 

If you don't mind checking every object in a layer (or need to do every object in a Layer) then ForEachObjectInLayer is great.

 

ForEachObject with the proper criteria can leverage all of the behinds the scene power of VW so that you don't have look at objects that you don't need to handle.

 

$0.02

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