Jump to content

Sloader

Member
  • Posts

    39
  • Joined

  • Last visited

Everything posted by Sloader

  1. I think I have answered my own question dxfunits=vs.GetPrefInt(301) vs.Message(dxfunits) The above returns 6 for meters
  2. Currently before I run a script that imports a batch of DXFs I import a single one manually to set the import properties (units and class mapping etc) I would like to get my scripts to do this. I think/hope I can use SetLastDXFImportOpt to do this - Is this correct? According to the appendices I can set the units using selector 301 but I can't see a reference for what integer to use the specify meters as the units - any ideas?
  3. Is the issue that the error isn't a python error but a VW message so the try code always gets executed? I think vs.ResetObject(h) will be usefull
  4. My scripts (one to create the massing models and one to set the roofs to pitched) were working but now, presumably due to a service pack change, the pitched roof one no longer results in pitched roofs. As below the roofs are set to be pitched but not drawn pitched, If I paste the massing models into a new drawing VW tries to draw pitched roofs but fails on some and I get the repeating error messages - but now there are more messages so its even more irritating. def trypitched(h):#try making pitched roofs try: vs.SetRField(h,'Massing Model','DrawPitchedRoof',True) except: pass vs.ForEachObject(trypitched, "((PON='Massing Model'))" ) #loop for all the massing models DEMO.vwx
  5. ""((SEL=True))" Doesn't work "((SEL=True))" Does work "((L='XX-ZZ-P-G-OS_MasterMap Fills-3D-2'))" Does work ((L='XX-ZZ-P-G-OS_MasterMap Fills-3D-2')) From the criteria builder doesn't work (language is set to python) - I write the criteria by hand as the builder has never worked and was one of the issues that really slowed me down when first trying to write scripts. If I wrap it in double quotes it does work "((L='XX-ZZ-P-G-OS_MasterMap Fills-3D-2'))" I can see why my original criteria didn't work, though I was following a previous example that did work - "T=LOCUS"
  6. The send to surface command fails when I run it with a large number of polygons so I was hoping to loop though all my polygons using a script. The script below is my attempt but it doesn't make anything happen. dtmL=vs.GetObject('XX-ZZ-M-U-LiDAR_DTM') hdtm=vs.DTM6_GetDTMObject(dtmL,True) def SendSurface(h): vs.DTM6_SendToSurface(hdtm, h, 0) vs.ForEachObject(SendSurface, "L=XX-ZZ-P-G-OS_MasterMap Fills-3D-2" )
  7. It makes little sense to me that the python escape character is /n yet a path with /n works fine whilst a path with /N doesn't. Also I am not sure why it used to work fine on MAC but when transferring my scripts to PC it wouldn't run. Is there a reliable way to include a file path that won't get escaped by python due to any of the special characters ?
  8. Adding and extra "\" does make the compiler happy but I have already changed the name to "nnr" which works fine, both options seem unnecessary. I was interested if my script is incorrect - I assumed the contents between ' ' would be interpreted as a string LNR = vs.ImportDXFDWGFile('C:\DOCs\SCRIPT\\NNR.dxf', isBatch)
  9. This line (on its own as a test but also as part of a bigger script) compiles fine LNR = vs.ImportDXFDWGFile('C:\DOCs\SCRIPT\LNR.dxf', isBatch) But if I change the file to NNR.dxf (national and local nature reserves) the script doesn't compile and I get a error as below which makes no sense to me as all I change is an L to an N NNR = vs.ImportDXFDWGFile('C:\DOCs\SCRIPT\NNR.dxf', isBatch) it even works with lower case NNR NNR = vs.ImportDXFDWGFile('C:\DOCs\SCRIPT\nnr.dxf', isBatch)
  10. I am working with a schedule of development parcels. I have database rows that add up some calculations based on (summarized by) parcel numbers in a database record, each parcel is made up of sections with different densities, the densities are specified in the database record. Summing up for the area works fine and calculating the total units works fine as its the sum of area*density for each section of the parcel. The issue I am having is in trying to calculate the resulting density for each parcel. If I sum up units/density I obviously get numbers that make no sense, if I have 2 sections of a parcel at a density of 30 the overall density isn't 60. Essentially I want perform calculations on the summed values in the other rows not make calculations for each part then add them up.
  11. We often receive base-mapping as DWGs, one of the supply options has layer names that do not translate into class names correctly. Names like "Road Or Track_Structure , Manmade , Bridge" get translated to something like "$TD_AUDIT_GENERATED_(A9)" which isn't very helpful. AutoCAD and QGIS interpret the names correctly and if I re-export from QGIS as a DXF with the commas replaced the names are interpreted ok.
  12. @DomC The "Try Except" approach works nicely so I have managed to get VW to do what I want and learnt something new in Python. I am still using the "Pitched" attribute from GIS so I can prevent buildings above or below a certain size from having pitched roofs but I should now be able to relax the restriction on how complex a roof I let it try and make pitched. try: vs.SetRField(h2,'Massing Model','DrawPitchedRoof',Pitched) except: pass
  13. The try / except approach looks ideal - When I get time I'll try setting the roof to pitched (True) and false if it fails The something heavy on the key option was explored E7 S7 of the Simpsons which clearly demonstrates some of the drawbacks of this approach
  14. Script below is cleaned up a bit. It now works with heights from my records and I have got GIS to do some guessing about which lines are too complex for a pitched roof in addition to cleaning up angles near 0 or 90. There will still be many polylines that are too complex so it would be good to suppress the failure messages so I don't have to sit and hold the return key whilst it runs, this would also mean I can relax the inputs on which polylines it tries to add a pitched roof to. storeyht=3 vs.SelectObj("T=GROUP") vs.Ungroup() def gone(h1): vs.ConvertToPolygon(h1, 0) vs.ForEachObject(gone, "T=POLYLINE" ) #loop for all the polylines and convert them to polygons def extrudebuildings(h):#make massing model buidlings based on records RecName=vs.GetName(vs.GetRecord(h,1)) Pitched=vs.GetRField(h, RecName,'PITCHED')#Get pitched boolean from record AOD=vs.GetRField(h, RecName,'TM_mean')#Get AOD height from record TM=eval(vs.GetRField(h, RecName,'TM_mean'))#convert AOD height to number SM=eval(vs.GetRField(h, RecName,'SM_max'))#Get max surface height as number BHT=SM-TM Storeys = ((SM-TM)-2)/storeyht Floors = vs.Round(Storeys) vs.CreateCustomObjectPath('Massing Model', h, None) h2 = vs.LNewObj() # get handle to new massing model vs.SetRField(h2,'Massing Model','2Ddisplay','Roof') vs.SetRField(h2,'Massing Model','Height',BHT) vs.SetRField(h2,'Massing Model','NumFloors',Floors) vs.SetRField(h2,'Massing Model','WallMatl','') vs.SetRField(h2,'Massing Model','Custom Roof','False') vs.SetRField(h2,'Massing Model','Overhang','0.3') vs.SetRField(h2,'Massing Model','RoofThk','0.3') vs.SetRField(h2,'Massing Model','RoofMatl','') vs.SetRField(h2,'Massing Model','DrawPitchedRoof',Pitched) vs.SetRField(h2,'Massing Model','EaveStyle','Square') vs.SetRField(h2,'Massing Model','RoofPitch','35') vs.SetRField(h2,'Massing Model','DrawFloorLevels','True') vs.SetRField(h2,'Massing Model','FloorThk','0.3') vs.SetRField(h2,'Massing Model','Use Site Modifiers','False') vs.SetRField(h2,'Massing Model','Use Fence','True') vs.SetRField(h2,'Massing Model','Fence offset','0.02') vs.SetRField(h2,'Massing Model','Use Shadow','False') vs.Move3DObj(h2, 0, 0, AOD) vs.ForEachObject(extrudebuildings, "T=POLY" ) #loop for all the polygons
  15. I am trying to create a site model that has a hole in it. The single crop object does have a hole but the resulting donut is more of a cake. Can it be done without cutting a thin slice out of the donut?
  16. When creating massing models some don't work because of the line geometry, this is fine but can I let VW ignore the issues without me holding down the return key?
  17. I found my error but can't see how to delete this topic My eventual goal is to build a set of massing models based on polygons with records for height etc. I can't see anything in the help files for the massing model custom object so what I have so far is based on exporting a script from a file with massing models in it. It looks like I should be able to change the fields for number of floors and height etc based on the records once I have got it to build massing models. So far what I have runs and creates massing models but they don't show on screen or export, I can select them and see their properties but there is clearly something very wrong with them. vs.SelectObj("T=GROUP") vs.Ungroup() def gone(h1): vs.ConvertToPolygon(h1, 0) vs.ForEachObject(gone, "T=POLYLINE" ) #loop for all the polylines and convert them to polygons def extrudebuildings(h):#Extrude buidlings based on records vs.CreateCustomObjectPath('Massing Model', h, none) h2 = vs.LNewObj() # get handle to new symbol instance vs.Record(vs.LNewObj(),'Massing Model'); vs.SetRField(vs.LNewObj(),'Massing Model','2Ddisplay','Roof'); vs.SetRField(vs.LNewObj(),'Massing Model','Height','6.096'); vs.SetRField(vs.LNewObj(),'Massing Model','NumFloors','2'); vs.SetRField(vs.LNewObj(),'Massing Model','WallMatl',''); vs.SetRField(vs.LNewObj(),'Massing Model','Custom Roof','False'); vs.SetRField(vs.LNewObj(),'Massing Model','Overhang','0.3048'); vs.SetRField(vs.LNewObj(),'Massing Model','RoofThk','0.3048'); vs.SetRField(vs.LNewObj(),'Massing Model','RoofMatl',''); vs.SetRField(vs.LNewObj(),'Massing Model','DrawPitchedRoof','False'); vs.SetRField(vs.LNewObj(),'Massing Model','EaveStyle','Square'); vs.SetRField(vs.LNewObj(),'Massing Model','RoofPitch','35'); vs.SetRField(vs.LNewObj(),'Massing Model','DrawFloorLevels','True'); vs.SetRField(vs.LNewObj(),'Massing Model','FloorThk','0.3048'); vs.SetRField(vs.LNewObj(),'Massing Model','Use Site Modifiers','False'); vs.SetRField(vs.LNewObj(),'Massing Model','Use Fence','True'); vs.SetRField(vs.LNewObj(),'Massing Model','Fence offset','0.0254'); vs.SetRField(vs.LNewObj(),'Massing Model','Use Shadow','False'); vs.ForEachObject(extrudebuildings, "T=POLY" ) #loop for all the polygons
  18. Move3DObj does work, many thanks. I see its listed right by Move3D in the Function reference and I still didn't spot it. I also seem to be missing something about how to use the search tool in the procedures dialogue within VW.
  19. I have the script below which places, scales and rotates tree symbols based on a set of 2d Loci created in GIS. I would like to set the Z position of the symbols based on an attribute but can't get it to work. I am trying to use Move3D as below but no joy. def ReplaceRAND1s(h):#Function to replace all loci from imported shapefile with scaled canopy symbols rand=vs.GetRField(h, 'TreePointsForSymbolsRec','RAND_COLOU')#Get the random colour for the canopy loci sym= vs.Concat('Canopy-'+ rand)#Convert the colour code to canopy symbol name ScaleX=vs.GetRField(h, 'TreePointsForSymbolsRec','RAD')#Get scale from loci record ScaleY=vs.GetRField(h, 'TreePointsForSymbolsRec','RAD')#Get scale from loci record ScaleZ=vs.GetRField(h, 'TreePointsForSymbolsRec','rvalue_1')#Get tree height from loci record AOD=vs.GetRField(h, 'TreePointsForSymbolsRec','DTM_1')#Get AOD height from loci record X, Y = vs.GetLocPt(h)#Get location from loci to place symbol randrot= vs.Random()*100 #create a random number to rotate the symbol by vs.Symbol(sym, X, Y, randrot) # place symbol based on loci postion, random colour and random rotation vs.Move3D(0, 0, AOD) h2 = vs.LNewObj() # get handle to new symbol instance vs.SetObjectVariableInt(h2, 101, 3) #Set symbol scaling to asymetric vs.SetObjectVariableReal(h2, 102, ScaleX)#Set X scale vs.SetObjectVariableReal(h2, 103, ScaleY)#Set Y scale vs.SetObjectVariableReal(h2, 104, ScaleZ)#Set Z scale/ height vs.DelObject(h)#clean up loci vs.ForEachObject(ReplaceRAND1s, ("T=LOCUS")) #loop for all the loci in the file TreeLoci.vwx
  20. Yes, I import shapefiles frequently - the importer is flakey but does mean you have records to to use for things like scaling tree symbols or extruding buildings which you don't get with DWG/DXF. vs.ImportDXFDWGFile is a pain as you can't (as far as I know) set the options like units and prefixes from the script. I'll look at adding some feedback. Doing some digging it looks like I might be able to use vs.SetLastDXFImportOpt(selector, value) to sort out my DXF imports
  21. vs.LNewObj() is the Key - no idea how I would have found it, I see its filed under document list handling which now makes sense. Better than doing receptive tasks manually, but VW could be more accessible. I need to spend the time to figure out a proper environment with debugging etc but that looks painful. I can't see a way to import a shapefile which is a shame. Code below seems to work - Takes tree canopy points created by a GIS script from LiDAR def ReplaceRAND1s(h):#Function to replace all loci from imported shapefile with scaled canopy symbols rand=vs.GetRField(h, 'TreePointsForSymbolsRec','RAND_COLOU')#Get the random colour for the canopy loci sym= vs.Concat('Canopy-'+ rand)#Convert the colour code to canopy symbol name ScaleX=vs.GetRField(h, 'TreePointsForSymbolsRec','RAD')#Get scale from loci record ScaleY=vs.GetRField(h, 'TreePointsForSymbolsRec','RAD')#Get scale from loci record ScaleZ=vs.GetRField(h, 'TreePointsForSymbolsRec','rvalue_1')#Get height from loci record X, Y = vs.GetLocPt(h)#Get location from loci to place symbol randrot= vs.Random()*100 #create a random number to rotate the symbol by vs.Symbol(sym, X, Y, randrot) # place symbol based on loci postion, random colour and random rotation h2 = vs.LNewObj() # get handle to new symbol instance vs.SetObjectVariableInt(h2, 101, 3) #Set symbol scaling to asymetric vs.SetObjectVariableReal(h2, 102, ScaleX)#Set X scale vs.SetObjectVariableReal(h2, 103, ScaleY)#Set Y scale vs.SetObjectVariableReal(h2, 104, ScaleZ)#Set Z scale/ height vs.DelObject(h)#clean up loci vs.ForEachObject(ReplaceRAND1s, "T=LOCUS" ) #loop for all the loci in the file
  22. Gotcha! thanks The loop just deletes everything it created. This also explains why I was getting confusing results trying to attach a record to the new symbols. Now I am struggling with attaching the record to the new symbol and transferring data into the values def ReplaceLOCI(h): ScaleX=vs.GetRField(h, 'canopyPNTSRec','RAD') ScaleY=vs.GetRField(h, 'canopyPNTSRec','RAD') ScaleZ=vs.GetRField(h, 'canopyPNTSRec','rvalue_1') X, Y = vs.GetLocPt(h) CreatedSymbol=vs.Symbol('Canopy-1', X, Y, 0) SymbolHandle= vs.GetObject(CreatedSymbol) vs.SetRecord(SymbolHandle,'canopyPNTSRec') vs.SetRField(SymbolHandle, 'canopyPNTSRec','RAD', ScaleZ) vs.DelObject(h) vs.ForEachObject(ReplaceLOCI, "T=Locus" )
  23. The code supplied below doesn't work as if you have the vs.DelObject(h) line in it deletes the newly created symbols as well as the loci, which doesn't make sense to me. When the new symbol is inserted that object seems to take the reference of h. If I run a later line referencing h such as vs.SetRecord(h,'canopyPNTSRec') the function is applied to the new symbol which would be workable if I could set the field values based on my ScaleX, ScaleY and ScaleZ variables def ReplaceRAND1s(h): X, Y = vs.GetLocPt(h) vs.Symbol(newsym1, X, Y, 0) vs.DelObject(h)
  24. After hours of searching I did find SetObjectVariable and verified by looking in a python script exported by VW. The below assumes I have manually converted all loci to symbols so attaching records and transferring the values from loci to new symbols is the next bit to look at. Cheers again def ReplaceRAND1s(h): X, Y = vs.GetLocPt(h) rand=vs.GetRField(h, 'canopyPNTSRec','RAND_COLOU') sym= vs.Concat('Canopy-'+ rand) ScaleX=vs.GetRField(h, 'canopyPNTSRec','RAD') ScaleY=vs.GetRField(h, 'canopyPNTSRec','RAD') ScaleZ=vs.GetRField(h, 'canopyPNTSRec','rvalue_1') symh= vs.Symbol(sym, X, Y, 0) vs.SetObjectVariableInt(symh, 101, 3) vs.SetObjectVariableReal(symh, 102, ScaleX) vs.SetObjectVariableReal(symh, 103, ScaleY) vs.SetObjectVariableReal(symh, 104, ScaleZ) vs.ForEachObject(ReplaceRAND1s, "L='canopyPNTS'" )
  25. Thanks for the help I saw that placing a symbol at each of the loci would be easier but the next step is to scale the symbol based on a field value so I don't want to lose the records. The correct usage of vs.SetHDef(h, vs.GetObject(newsym1)) is useful to know as I could replace all loci with a symbol before I run the script. I have cleaned up the concept a little so I don't need 5 loops as I can pick the right symbol as part of the one function Currently struggling with the scaling as the below doesn't scale the symbol in place and I expect its to do with coordinates def ReplaceRAND1s(h): rand=vs.GetRField(h, 'canopyPNTSRec','RAND_COLOU') sym= vs.Concat('Canopy-'+ rand) vs.SetHDef(h, vs.GetObject(sym)) ptXY = vs.GetSymLoc(h) PtX = ptXY[0] PtY = ptXY[1] vs.HScale2D(h, PtY, PtX, 1, 1, 0) vs.ForEachObject(ReplaceRAND1s, "L='canopyPNTS'" )
×
×
  • Create New...