Jump to content

DomC

Member
  • Posts

    611
  • Joined

  • Last visited

Posts posted by DomC

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

  2. PyCharm. But not integrated any vs modules ... handy to check those intents.

    To keep it alive. The working result:

    A simple script to paste all symbols of a folder on the active layer. The idea is to enlarge it sometime with text of the symbol name or making layers for every symbol folders to get a nice, printable preview of all symbols. I think code could be still more reduced and optimized.

    def placesymb(name,x,y,spalten):
    reihen=num/spalten
    vs.Symbol(name,x,y,0)
    return()
    
    symid = vs.FInFolder( vs.GetObject( 'Folder-1' ) )
    x=0
    y=0
    num=0
    spalten=4 #total spalten
    zeile=0 #aktuelle zeile
    versatz=2 # einheit beachten!
    n=0
    
    while vs.GetTypeN(symid)==16:
    folder=vs.GetName(vs.GetParent(symid))
    symname=vs.GetName(symid)
    placesymb(symname,x,y,spalten)
    symid=vs.NextSymDef(symid)
    sym=symid
    x=x+versatz
    zeile=int(n/spalten)
    y=zeile*versatz	
    if n % spalten ==0:
    	x=0
    
    n=n+1
    

    or another one, to place all symbols of a folder on a activated area. The symbol loops till the area is filled:

    def placesymb(name,x,y,spalten):
    vs.Symbol(name,x,y,0)
    return()
    
    versatz = 4
    rotation = 0
    folder='Folder-1'	
    area = vs.FSActLayer()
    symid = vs.FInFolder(vs.GetObject(folder))
    
    
    p1,p2=vs.GetBBox(area)
    x1=p1[0]
    y1=p2[1]
    x=x1
    y=y1
    num=0
    breite=abs(p2[0]-p1[0])
    hoehe=abs(p2[1]-p1[1])
    
    zeile=0
    spalte=0
    i=0
    spalten=int(breite/versatz)
    
    
    zeilen=(hoehe/versatz)
    n=0
    
    while spalte <= spalten and zeile <=zeilen:
    
    folder=vs.GetName(vs.GetParent(symid))
    symname=vs.GetName(symid)
    p=x,y
    if vs.PtInPoly(p, area) == True:
    	placesymb(symname,x,y,spalten)
    symid=vs.NextSymDef(symid)
    
    if vs.GetTypeN(symid)!=16:
    	symid=vs.FInFolder(vs.GetObject(folder))
    x=spalte*versatz+x1		
    zeile=int(n/spalten)
    if spalte % spalten ==0:
    	spalte=0
    spalte=spalte+1	
    y=zeile*versatz+y1
    n=n+1	
    i=i+1	

  3. Cool, great hint. GetParent() does the job perfectly.

    symid = vs.FInFolder( vs.GetObject( 'Folder-1' ) )
    
    while vs.GetTypeN(symid)==16:
    folder=vs.GetName(vs.GetParent(symid))
    symname=vs.GetName(symid)
    vs.AlrtDialog('symname: '+symname+' parent :'+folder)
    symid=vs.NextSymDef(symid)
    sym=symid
    
    if vs.GetTypeN(sym)!=16:
    	vs.AlrtDialog('keine weiteren Symbole im Ordner')

  4. Hi

    I try to get a list of symbols in a specific symbol folder on the active document. I searched the script reference and the internet. It sould be possible by using:

    id, number = vs.BuildResourceList(16, -1, foldername)

    But the result is always an empty list. All positive index values works but lists all symbols in all folders. I can't find out, what I am doing wrong.

    Would be fantastic if anyone can help. The following script, do what I want (not finally, it's just a test, the alert box is my debug workflow :-)

    Best Regards

    Dom

    folderlistid,listlength = vs.BuildResourceList(92, 0,'')
    
    i=0
    x=1
    
    while i < listlength:
    foldername = vs.GetNameFromResourceList(folderlistid,x)
    vs.AlrtDialog('foldername :'+foldername)
    symlistid, symnum='keine', 0
    symlistid, symnum = vs.BuildResourceList(16, -1, foldername) #index -1 do not work?	#index 
    
    n=0
    o=1
    while n < symnum:
    	symname= vs.GetNameFromResourceList(symlistid,o)
    	vs.AlrtDialog('symname: '+str(symname))
    	n=n+1
    	o=o+1
    i=i+1
    x=x+1
    
    n=0
    i=2
    while n < 20:
    foldername = vs.GetNameFromResourceList(folderlistid,x)
    symlistid, symnum = vs.BuildResourceList(16, i, 'Folder-1') #just to test, if maybe an index from +2 till -20 works
    symname= vs.GetNameFromResourceList(symlistid,1)
    vs.AlrtDialog('symname: index'+str(i)+str(symname))
    n=n+1
    i=i-1

  5. Hi

    I try to use this Function, but failing by fuguring out the right parameters/variables. I do not understand if i have to get the Variables from an other action/function or if I just missing the right values.

    Very nice if anyone could help

    Thanks

    This is, what the FunctionReference says:

    VectorScript Reference.html

    PROCEDURE AlignDistribute2D

    ( MenuAction :LONGINT;

    AlignDist2DParms :LONGINT

    ) ;

    Python:

    def vs.AlignDistribute2D(MenuAction, AlignDist2DParms):

    return None

    or here:

    Python:

    AlignDist2DParms = vs.AlignDistribute2D(MenuAction)

    I try to do, something in this direction (Script to Distribute, with a fix offset by expanding the limits):

    import vs
    
    links,rechts,unten,oben,xtotal,ytotal=0,0,0,0,0,0 
    anzahl=vs.NumSelectedObjects()
    
    # Box auslesen und x, y ausgeben
    def xy():
    p1,p2=vs.GetBBox(h)
    x=abs(p1[0]-p2[0])
    y=abs(p1[1]-p2[1])
    xmin=p1[0];	xmax=p2[0]; ymin=p1[1]; ymax=p2[1]
    return(x,y,xmin,xmax,ymin,ymax)
    
    
    #vs.AlrtDialog(anzahl)
    
    i=1
    h=vs.FSActLayer()	 
    while h != None and i <= anzahl:
    x,y,xmin,xmax,ymin,ymax=xy()
    if links>xmin:
    	links=xmin
    if rechts		rechts=xmax
    if unten>ymin:
    	unten=ymin
    if oben		oben=ymax
    #vs.AlrtDialog(xmin,' ', xmax)
    xtotal=xtotal+x
    ytotal=ytotal+y
    h=vs.NextSObj(h)
    i+=1	
    
    rx_abs=links+xtotal
    vs.Locus(rx_abs,0)
    # vs.AlignDistribute2D(??)  #??????
    vs.LNewObj(h)
    vs.DelObject(h)
    

  6. The required constants in Python are True, False and None (NIL ist None)

    I got something like this in one of my python-script-testing, that works.

    tempHandle1 = vs.LNewObj()
    tempHandle2 = None
    objectHandle = vs.CreateCustomObjectPath('Part', tempHandle1, tempHandle2)

  7. In case someone cares

    Dialog box still not working, but another test with the python module subprocess to open a system window, works instead.

    A script test to export the classes of the active document to a textfile and open the export folder in a finder windows. This is an example of feature (open a sys folder) wich would be not possible just with the function offered by classic "pascal-vectorscript".

    import codecs
    import os.path
    import os
    
    homeDir = os.path.join(os.path.expanduser("~"))
    Pfad = '{}/Documents/TempVWFiles'.format(homeDir)
    
    FileName=vs.GetFName()
    
    File = homeDir+'/Documents/TempVWFiles/'+'Klassenliste_'+FileName+'.txt'
    
    d = os.path.dirname(Pfad)
    if not os.path.isdir(Pfad):
    os.mkdir(Pfad)
    
    
    
    KlassenAnzahl=vs.ClassNum()
    
    
    f = codecs.open(File, "w", "utf-8")
    x = 1
    while x <= KlassenAnzahl:
    Klasse = vs.ClassList(x)
    x= x+1
    f.write('\''+Klasse+'\''+',')
    f.close()
    vs.AlrtDialog('Die Datei wurde an folgende Stelle gespeichert:'+File)
    
    import subprocess
    import sys
    
    path=Pfad
    if sys.platform == 'darwin':
       def openFolder(path):
           subprocess.check_call(['open', '--', path])
    elif sys.platform == 'linux2':
       def openFolder(path):
           subprocess.check_call(['gnome-open', '--', path])
    elif sys.platform == 'win32':
       def openFolder(path):
           subprocess.check_call(['explorer', path])
    
    openFolder(path)

  8. Hi

    It looks that it should be possible to use all functionality of the standard python 3.3 inside Vectorworks. The python package is included inside Vectorworks.

    Just to check this out with a simple dialogue window i tried to create a python based message windows inside Vectorworks -without any success. Maybe i trie to practice with the wrong example (Dialoge Box)

    Somehow module os.path.basename fails. Anyone else tried to do this?

    Example Code which do not work inside/outside a Vectorscript. But it works from the python 3 mac terminal.

    import sys
    from tkinter import *
    def mhello():
       pass
       return
    
    mGui = Tk()
    ment = StringVar()
    
    mGui.geometry('450x450+500+300')
    mGui.title('python tkinter message')
    
    mlabel = Label(mGui,text ='my label').pack()
    
    mbutton = Button(mGui,text ='ok',command = mhello,fg = 'red',bg='blue').pack()
    
    mEntry = entry().pack 

    This code is from a very simple python script. It checks if the classes of the active document are part of a standard class list. I post this here, because posting some code is something that makes it more interesting to read a thread. It shows the code with the working vectorscript alert dialogue.

    KlassenAnzahl=vs.ClassNum()
    
    Standardklassen = ('Standardklasse1', 'Standardklasse2', 'Standardklasse2', 'Standardklasse3', 'Standardklasse4')
    
    NichtStandard =''
    x = 1
    while x <= KlassenAnzahl:
    Klasse = vs.ClassList(x)
    istKlasseVorhanden = Klasse in Standardklassen
    x= x+1
    if istKlasseVorhanden == 0:
    	NichtStandard = NichtStandard + '  /  '+ Klasse
    
    vs.AlrtDialog(NichtStandard)

  9. Wow, a stupid alpha error.

    (vectorscript is not case-sensitive)

    Thank you so much!

    Just to complete, the running code:

    import vs
    
    def Test():
    Text = 'Hello Vectorworks.'
    vs.AlrtDialog( Text+' This should work, or not?')
    vs.MoveTo(0,0)
    vs.LineTo(0,500)
    Test()

  10. Hello

    I wanted to port some of my Document-Based Pascal Scripts to Python. Not because it ist necessary, just to learn something.

    I tried just to build a Python example with some commands from the Vectorworks Namespace.

    def Test():
       Text = 'Hello Vectorworks.'
       vs.AlrtDialog( Text+' This should work, or not?')
       vs.moveto(0,0)
       vs.Lineto(0,500)
    Test()

    The "AlrtDialog" seems to work. vs.moveto and vs.lineto do not want

    Many thanks for some ideas!

    Dom

    Error Message:

    Traceback (most recent call last):

    File "", line 7, in

    File "", line 5, in in Test

    AttributeError: 'module' object has no attribute 'moveto'

×
×
  • Create New...