Jump to content

Gelde-Aart

Member
  • Posts

    21
  • Joined

  • Last visited

Posts posted by Gelde-Aart

  1. After some further testing it seems that the issue is not Python (even got back to Vectorscript for this...) , but the tool being event driven (forgot to mention...). when the tool is  'normal' (for both Python and Vectorscript) a parameter will be read. Converting the tool  to an event driven one raises errors...

    • Like 1
  2. Hi Tui,

     

    Below an example script (I had to port and clean it from Vectorworks 2013):

     

    kLB001			= 4
    kPB_Expand		= 5
    kPB_Collapse	= 6
    	
    import vs
    
    def dialogHandler(item, data):
    	if item == 12255:
    		nCol = vs.InsertLBColumn(dialID,kLB001,0,'Item',150)
    		bResult = vs.SetLBControlType(dialID,kLB001,0,1)
    		bResult = vs.SetLBItemDisplayType(dialID,kLB001,0,3)
    		
    		#Some Lines to fill the listbrowser
    		nItem = vs.InsertLBItem(dialID,kLB001,0,'2D-Axis')
    		nItem = vs.InsertLBItem(dialID,kLB001,1,'2D-Cap')
    		nItem = vs.InsertLBItem(dialID,kLB001,2,'2D-Housing-Back')
    		nItem = vs.InsertLBItem(dialID,kLB001,3,'2D-Housing-Frame')
    		nItem = vs.InsertLBItem(dialID,kLB001,4,'2D-Housing-Glass')
    		nItem = vs.InsertLBItem(dialID,kLB001,5,'2D-Leaf-Back')
    		nItem = vs.InsertLBItem(dialID,kLB001,6,'2D-Leaf-Frame')
    		nItem = vs.InsertLBItem(dialID,kLB001,7,'2D-Leaf-Glass')
    		nItem = vs.InsertLBItem(dialID,kLB001,8,'3D-Axis')
    		nItem = vs.InsertLBItem(dialID,kLB001,9,'3D-Cap')
    		nItem = vs.InsertLBItem(dialID,kLB001,10,'3D-Housing-Frame')
    		nItem = vs.InsertLBItem(dialID,kLB001,11,'3D-Housing-Glass')
    		nItem = vs.InsertLBItem(dialID,kLB001,12,'3D-Leaf-Frame')
    		nItem = vs.InsertLBItem(dialID,kLB001,13,'3D-Leaf-Glass')
    		
    		vs.EnableLBSorting(dialID,kLB001,False)
    		vs.SetLBHierDispColumn(dialID,kLB001,0)
    		vs.EnableLBHierDisplay(dialID,kLB001,True)
    		global numLBItems #has to be a global, otherwise it won't work...
    		numLBItems = vs.GetNumLBItems(dialID,kLB001)
    		
    	elif item == kLB001:
    		LBrecursive = True
    		bResult = vs.GetLBEventInfo(dialID,kLB001,LBeventType,LBrowIndex,LBcolumIndex)
    		if vs.HierLBItemIsClosed(dialID,kLB001,LBrowIndex):
    			numbRedisplItems = vs.HierLBItemOpened(dialID,kLB001,LBrowIndex,False)
    		else:
    			vs.HierLBItemClosed(dialID,kLB001,LBrowIndex,False)
    
    	elif item == kPB_Expand:
    		for i in range(numLBItems):
    			if vs.HierLBItemIsClosed(dialID,kLB001,i):
    				numbRedisplItems = vs.HierLBItemOpened(dialID,kLB001,i,True)
    
    	elif item == kPB_Collapse:
    		for i in range(numLBItems):
    			if vs.HierLBItemIsClosed(dialID,kLB001,i) == False:
    				vs.HierLBItemClosed(dialID,kLB001,i,True)
    
    def rundialog():
    	global dialID
    	dialID = vs.CreateResizableLayout('Test Listbrowser',True,'OK','Cancel',False,False)
    	vs.CreateLB(dialID,kLB001,60,20)
    	
    	vs.CreatePushButton(dialID,kPB_Expand,'Expand')
    	vs.CreatePushButton(dialID,kPB_Collapse,'Collapse')
    	
    	vs.SetFirstLayoutItem(dialID,kLB001)
    	vs.SetRightItem(dialID,kLB001,kPB_Expand,0,0)
    	vs.SetBelowItem(dialID,kPB_Expand,kPB_Collapse,0,0)
    	
    	if vs.RunLayoutDialog(dialID,dialogHandler) == 1:
    		pass
    		
    rundialog()

    Cheers,

     

    Gelde-Aart

    • Like 1
  3. Hi Jonas,

     

    From Vectorworks 2019 and newer it is possible to create a image based texture by using CreateTextureBitmapD (before you had to use a dummy texture...)

    #Part 1 - import and convert image
    hPaint = vs.ImportImageFile(thePath, 0,0) #Needs to be deleted afterwards
    hImage = vs.CreateImageFromPaint(hPaint, 'Just_a_name')
    
    #Part 2 - Create ShaderRecord and convert to TextureBitmap
    hShaderRec = vs.CreateShaderRecord(hTexture, 1, 41) #1 = Color image
    hTextureBitMap = vs.CreateTextureBitmapD( hShaderRec)
    
    #Part 3 - Connect the image to the TextureBitmap
    vs.SetObjectVariableHandle(hTextureBitMap, 528, hImage) #Were the magic happens!

    Hope this helps.

    🙂

    Gelde-Aart

    • Like 2
  4. To assign a texture to the 3D object use the vs.SetTextureRefN(obj, textureRef, texPartID, texLayerID), so your script would look like:

     

    vs.BeginPoly3D()
    vs.Add3DPt((-5, 0, -5))
    vs.Add3DPt(( 5, 0, -5))
    vs.Add3DPt(( 5, 0,  5))
    vs.Add3DPt((-5, 0,  5))
    vs.Add3DPt((-5, 0, -5))
    vs.EndPoly3D()
    image = vs.LNewObj()
    
    textureRef = vs.Name2Index("Test texture")
    
    texPartID = 0
    texLayerID = 0
    vs.SetTextureRefN(image, textureRef, texPartID, texLayerID)

     In the above the texPartID is the primary and the texLayerID is about the base object (0) or decals(1 and further).

    • Like 1
  5. Thanks!

    What I'm after is from a PIO, using a button to show a dialog like the Subtract solid, to 'highlight' which part of the object will be edited.

     

    I already thought about a temporary object, but it only got created after the dialog closed... perhaps you know a way to create a temporary rectangle within the Begin and Endcontext()? A second option would be to use a SymbolDisplayControl within the dialog, but somehow that seems like an overkill...

     

    Any Ideas for the first option are welcome!

×
×
  • Create New...