revit可视化编程插件Dynamo使用手册_第1页
revit可视化编程插件Dynamo使用手册_第2页
revit可视化编程插件Dynamo使用手册_第3页
revit可视化编程插件Dynamo使用手册_第4页
revit可视化编程插件Dynamo使用手册_第5页
已阅读5页,还剩56页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、DynamoLanguageManualContentsLanguageBasicsGeometryBasicsGeometricPrimitivesVectorMathRangeExpressionsCollectionsFunctionsMathCurves:InterpretedandControlPointsTranslation,Rotation,andOtherTransformationsConditionalsandBooleanLogicLoopingReplicationGuidesCollectionRankandJaggedCollectionsSurfaces:Int

2、erpreted,ControlPoints,Loft,RevolveGeometricParameterizationIntersectionandTrimGeometricBooleansA-1.Appendix1:PythonPointGeneratorsIntroductionProgramminglanguagesarecreatedtoexpressideas,usuallyinvolvinglogicandcalculation.Inadditiontotheseobjectives,theDynamotextuallanguage(formerlyDesignScript)ha

3、sbeencreatedtoexpressdesignintentions.Itisgenerallyrecognizedthatcomputationaldesigningisexploratory,andDynamotriestosupportthis:wehopeyoufindthelanguageflexibleandfastenoughtotakeadesignfromconcept,throughdesigniterations,toyourfinalform.Thismanualisstructuredtogiveauserwithnoknowledgeofeitherprogr

4、ammingorarchitecturalgeometryfullexposuretoavarietyoftopicsinthesetwointersectingdisciplines.Individualswithmoreexperiencedbackgroundsshouldjumptotheindividualsectionswhicharerelevanttotheirinterestsandproblemdomain.Eachsectionisself-contained,anddoesntrequireanyknowledgebesidestheinformationpresent

5、edinpriorsections.TextblocksinsetintheConsolasfontshouldbepastedintoaCodeBlocknode.TheoutputoftheCodeBlockshouldbeconnectedintoaWatchnodetoseetheintendedresult.Imagesareincludedintheleftmarginillustratingthecorrectoutputofyourprogram.1:LanguageBasicsThisdocumentdiscussestheDynamotextualprogrammingla

6、nguage,usedinsideoftheDynamoeditor(sometimesreferredtoas“DynamoSandbox”).TocreateanewDynamoscript,opentheDynamoeditor,andselectthe“New”buttoninthe“FILES”group:ThiswillopenablankDynamograph.TowriteaDynamotextscript,doubleclickanywhereinthecanvas.Thiswillbringupa“CodeBlock”node.Inordertoeasilyseethere

7、sultsofourscripts,attacha“Watch”nodetotheoutputofyourCodeBlocknode,asshownhere:Lessismore.;Everyscriptisaseriesofwrittencommands.Someofthesecommandscreategeometry;otherssolvemathematicalproblems,writetextfiles,orgeneratetextstrings.Asimple,onelineprogramwhichgeneratesthequote“Lessismore.”looksliketh

8、is:WatchTheWatchnodeontheleftshowstheoutputofthescript.ThecommandgeneratesanewStringobject.StringsinDynamoaredesignatedbytwoquotationmarks(),andtheenclosedcharacters,includingspaces,arepassedoutofthenode.CodeBlocknodesarenotlimitedtogeneratingStrings.ACodeBlocknodetogeneratethenumber5420lookslikethi

9、s:5420;EverycommandinDynamoisterminatedbyasemicolon.Ifyoudonotincludeone,theEditorwilladdoneforyou.Alsonotethatthenumberandcombinationofspaces,tabs,andcarriagereturns,calledwhitespace,betweentheelementsofacommanddonotmatter.Thisprogramproducestheexactsameoutputasthefirstprogram:LessIsMore.;Naturally

10、,theuseofwhitespaceshouldbeusedtohelpimprovethereadabilityofyourcode,bothforyourselfandfuturereaders.Commentsareanothertooltohelpimprovethereadabilityofyourcode.InDynamo,asinglelineofcodeis“commented”withtwoforwardslashes,/.Thismakesthenodeignoreeverythingwrittenaftertheslashes,uptoacarriagereturn(t

11、heendoftheline).Commentslongerthanonelinebeginwithaforwardslashasterisk,/*,andendwithanasteriskforwardslash,*/./Thisisasinglelinecomment/*Thisisamultiplelinecomment,Watchwhichcontinuesformultiplelines.*/Allofthesecommentshavenoeffecton/theexecutionoftheprogram/ThislineprintsaquotebyMiesvanderRoheLes

12、sIsMore;WatchSofartheCodeBlockargumentshavebeenliteralvalues,eitheratextstringoranumber.Howeveritisoftenmoreusefulforfunctionargumentstobestoredindatacontainerscalledvariables,whichbothmakecodemorereadable,andeliminateredundantcommandsinyourcode.Thenamesofvariablesareuptoindividualprogrammerstodecid

13、e,thougheachvariablenamemustbeunique,startwithaloweroruppercaseletter,andcontainonlyletters,numbers,orunderscores,_.Spacesarenotallowedinvariablenames.Variablenamesshould,thougharenotrequired,todescribethedatatheycontain.Forinstance,avariabletokeeptrackoftherotationofanobjectcouldbecalledrotation.To

14、describedatawithmultiplewords,programmerstypicallyusetwocommonconventions:separatethewordsbycapitalletters,calledcamelCase(thesuccessivecapitallettersmimicthehumpsofacamel),ortoseparateindividualwordswithunderscores.Forinstance,avariabletodescribetherotationofasmalldiskmightbenamedsmallDiskRotationo

15、rsmall_disk_rotation,dependingontheprogrammersstylisticpreference.Tocreateavariable,writeitsnametotheleftofanequalsign,followedbythevalueyouwanttoassigntoit.Forinstance:quote=Lessismore.;Besidesmakingreadilyapparentwhattheroleofthetextstringis,variablescanhelpreducetheamountofcodethatneedsupdatingif

16、datachangesinthefuture.Forinstancethetextofthefollowingquoteonlyneedstobechangedinoneplace,despiteitsappearancethreetimesintheprogram.uoteWatchuoteuoteLessismore.Lessiseorw?Lessisuiorb.uote;esvanderRohethreetimes,j.Noticetheuseofthe+gsandvariablestogethertoformonecontinuousoutput./MyNEWfavoritearchi

17、tecturequoteWatchLessisabore.;,+quote+fLessisabore*Lessisabore.Lessisabor2:GeometryBasicsThesimplestgeometricalobjectintheDynamostandardgeometrylibraryisapoint.Allgeometryiscreatedusingspecialfunctionscalledconstructors,whicheachreturnanewinstanceofthatparticulargeometrytype.InDynamo,constructorsbeg

18、inwiththenameoftheobjectstype,inthiscasePoint,followedbythemethodofconstruction.Tocreateathreedimensionalpointspecifiedbyx,y,andzCartesiancoordinates,usetheByCoordinatesconstructor:/createapointwiththefollowingx,y,andz/coordinates:x=10;y=2.5;z=-6;p=Point.ByCoordinates(x,y,z);ConstructorsinDynamoaret

19、ypicallydesignatedwiththe“By”prefix,andinvokingthesefunctionsreturnsanewlycreatedobjectofthattype.Thisnewlycreatedobjectisstoredinthevariablenamedontheleftsideoftheequalsign,andanyuseofthatsameoriginalPoint.Mostobjectshavemanydifferentconstructors,andwecanusetheBySphericalCoordinatesconstructortocre

20、ateapointlyingonasphere,specifiedbythespheresradius,afirstrotationangle,andasecondrotationangle(specifiedindegrees):/createapointonaspherewiththefollowingradius,/theta,andphirotationangles(specifiedindegrees)radius=5;theta=75.5;phi=120.3;cs=CoordinateSystem.Identity();p=Point.BySphericalCoordinates(

21、cs,radius,theta,phi);Pointscanbeusedtoconstructhigherdimensionalgeometrysuchaslines.WecanusetheByStartPointEndPointconstructortocreateaLineobjectbetweentwopoints:/createtwopoints:p1=Point.ByCoordinates(3,10,2);p2=Point.ByCoordinates(-15,7,0.5);/constructalinebetweenp1andp2l=Line.ByStartPointEndPoint

22、(p1,p2);Similarly,linescanbeusedtocreatehigherdimensionalsurfacegeometry,forinstanceusingtheLoftconstructor,whichtakesaseriesoflinesorcurvesandinterpolatesasurfacebetweenthem./createpoints:p1=Point.ByCoordinates(3,10,2);p2=Point.ByCoordinates(-15,7,0.5);p3=Point.ByCoordinates(5,-3,5);p4=Point.ByCoor

23、dinates(-5,-6,2);p5=Point.ByCoordinates(9,-10,-2);p6=Point.ByCoordinates(-11,-12,-4);/createlines:l1=Line.ByStartPointEndPoint(p1,p2);l2=Line.ByStartPointEndPoint(p3,p4);l3=Line.ByStartPointEndPoint(p5,p6);/loftbetweencrosssectionlines:surf=Surface.ByLoft(l1,l2,l3);Surfacestoocanbeusedtocreatehigher

24、dimensionalsolidgeometry,forinstancebythickeningthesurfacebyaspecifieddistance.Manyobjectshavefunctionsattachedtothem,calledmethods,allowingtheprogrammertoperformcommandsonthatparticularobject.MethodscommontoallpiecesofgeometryincludeTranslateandRotate,whichrespectivelytranslate(move)androtatethegeo

25、metrybyaspecifiedamount.SurfaceshaveaThickenmethod,whichtakeasingleinput,anumberspecifyingthenewthicknessofthesurface.p1=Point.ByCoordinates(3,10,2);p2=Point.ByCoordinates(-15,7,0.5);p3=Point.ByCoordinates(5,-3,5);p4=Point.ByCoordinates(-5,-6,2);l1=Line.ByStartPointEndPoint(p1,p2);l2=Line.ByStartPoi

26、ntEndPoint(p3,p4);surf=Surface.ByLoft(l1,l2);/trueindicatestothickenbothsidesoftheSurface:solid=surf.Thicken(4.75,true);Intersectioncommandscanextractlowerdimensionalgeometryfromhigherdimensionalobjects.Thisextractedlowerdimensionalgeometrycanformthebasisforhigherdimensionalgeometry,inacyclicprocess

27、ofgeometricalcreation,extraction,andrecreation.Inthisexample,weusethegeneratedSolidtocreateaSurface,andusetheSurfacetocreateaCurve.p1=Point.ByCoordinates(3,10,2);p2=Point.ByCoordinates(-15,7,0.5);p3=Point.ByCoordinates(5,-3,5);p4=Point.ByCoordinates(-5,-6,2);l1=Line.ByStartPointEndPoint(p1,p2);l2=Li

28、ne.ByStartPointEndPoint(p3,p4);surf=Surface.ByLoft(l1,l2);solid=surf.Thicken(4.75,true);p=Plane.ByOriginNormal(Point.ByCoordinates(2,0,0),Vector.ByCoordinates(1,1,1);int_surf=solid.Intersect(p);int_line=int_surf.Intersect(Plane.ByOriginNormal(Point.ByCoordinates(0,0,0),Vector.ByCoordinates(1,0,0);3:

29、GeometriePrimitivesWhileDynamoiscapableofcreatingavarietyofcomplexgeometricforms,simplegeometricprimitivesformthebackboneofanycomputationaldesign:eitherdirectlyexpressedinthefinaldesignedform,orusedasscaffoldingoffofwhichmorecomplexgeometryisgenerated.Whilenotstrictlyapieceofgeometry,theCoordinateSy

30、stemisanimportanttoolforconstructinggeometry.ACoordinateSystemobjectkeepstrackofbothpositionandgeometrictransformationssuchasrotation,sheer,andscaling.CreatingaCoordinateSystemcenteredatapointwithx=0,y=0,z=0,withnorotations,scaling,orsheeringtransformations,simplyrequirescallingtheIdentityconstructo

31、r:/ereateaCoordinateSystematx=0,y=0,z=0,/norotations,sealing,orsheeringtransformationses=CoordinateSystem.Identity();CoordinateSystemswithgeometrictransformationsarebeyondthescopeofthischapter,thoughanotherconstructorallowsyoutocreateacoordinatesystemataspecificpoint,CoordinateSystem.ByOriginVeetors

32、:/ereateaCoordinateSystemataspeeifieloeation,/norotations,sealing,orsheeringtransformationsx_pos=3.6;y_pos=9.4;z_pos=13.0;origin=Point.ByCoordinates(x_pos,y_pos,z_pos);identity=CoordinateSystem.Identity();es=CoordinateSystem.ByOriginVeetors(origin,identity.XAxis,identity.YAxis,identity.ZAxis);Thesim

33、plestgeometricprimitiveisaPoint,representingazerodimensionallocationinthree-dimensionalspace.Asmentionedearlierthereareseveraldifferentwaystocreateapointinaparticularcoordinatesystem:Point.ByCoordinatescreatesapointwithspecifiedx,y,andzcoordinates;Point.ByCartesianCoordinatescreatesapointwithaspecif

34、iedx,y,andzcoordinatesinaspecificcoordinatesystem;Point.ByCylindricalCoordinatescreatesapointlyingonacylinderwithradius,rotationangle,andheight;andPoint.BySphericalCoordinatescreatesapointlyingonaspherewithradiusandtworotationangle.Thisexampleshowspointscreatedatvariouscoordinatesystems:/createapoin

35、twithx,y,andzcoordinatesx_pos=1;y_pos=2;z_pos=3;pCoord=Point.ByCoordinates(x_pos,y_pos,z_pos);/createapointinaspecificcoordinatesystemcs=CoordinateSystem.Identity();pCoordSystem=Point.ByCartesianCoordinates(cs,x_pos,y_pos,z_pos);/createapointonacylinderwiththefollowing/radiusandheightradius=5;height

36、=15;theta=75.5;pCyl=Point.ByCylindricalCoordinates(cs,radius,theta,height);/createapointonaspherewithradiusandtwoanglesphi=120.3;pSphere=Point.BySphericalCoordinates(cs,radius,theta,phi);ThenexthigherdimensionalDynamoprimitiveisalinesegment,representinganinfinitenumberofpointsbetweentwoendpoints.Lin

37、escanbecreatedbyexplicitlystatingthetwoboundarypointswiththeconstructorLine.ByStartPointEndPoint,orbyspecifyingastartpoint,direction,andlengthinthatdirection,Line.ByStartPointDirectionLength.p1=Point.ByCoordinates(-2,-5,-10);p2=Point.ByCoordinates(6,8,10);/alinesegmentbetweentwopointsl2pts=Line.BySt

38、artPointEndPoint(p1,p2);/alinesegmentatp1indirection1,1,1with/length10lDir=Line.ByStartPointDirectionLength(p1,Vector.ByCoordinates(1,1,1),10);Dynamohasobjectsrepresentingthemostbasictypesofgeometricprimitivesinthreedimensions:Cuboids,createdwithCuboid.ByLengths;Cones,createdwithCone.ByPointsRadiusa

39、ndCone.ByPointsRadii;Cylinders,createdwithCylinder.ByRadiusHeight;andSpheres,createdwithSphere.ByCenterPointRadius./createacuboidwithspecifiedlengthscs=CoordinateSystem.Identity();cub=Cuboid.ByLengths(cs,5,15,2);/createseveralconesp1=Point.ByCoordinates(0,0,10);p2=Point.ByCoordinates(0,0,20);p3=Poin

40、t.ByCoordinates(0,0,30);cone1=Cone.ByPointsRadii(p1,p2,10,6);cone2=Cone.ByPointsRadii(p2,p3,6,0);/makeacylindercylCS=cs.Translate(10,0,0);cyl=Cylinder.ByRadiusHeight(cylCS,3,10);/makeaspherecenterP=Point.ByCoordinates(-10,-10,0);sph=Sphere.ByCenterPointRadius(centerP,5);4:VectorMathObjectsincomputat

41、ionaldesignsarerarelycreatedexplicitlyintheirfinalpositionandform,andaremostoftentranslated,rotated,andotherwisepositionedbasedoffofexistinggeometry.Vectormathservesasakind-ofgeometricscaffoldingtogivedirectionandorientationtogeometry,aswellastoconceptualizemovementsthrough3Dspacewithoutvisualrepres

42、entation.asetofAtitsmostbasic,avectorrepresentsapositionin3Dspace,andisoftentimesthoughtofastheendpointofanarrowfromtheposition(0,0,0)tothatposition.VectorscanbecreatedwiththeByCoordinatesconstructor,takingthex,y,andzpositionofthenewlycreatedVectorobject.NotethatVectorobjectsarenotgeometricobjects,a

43、nddontappearintheDynamowindow.However,informationaboutanewlycreatedormodifiedvectorcanbeprintedintheconsolewindow:Watchl=s=1.0000002*0000003000000onstructaVectorobjectVector.ByCoordinates(1,2,3);v.X+v.Y+v.Z;mathematicaloperationsaredefinedonVectorobjects,allowingyoutoadd,subtract,multiply,andotherwi

44、semoveobjectsin3Dspaceasyouwouldmoverealnumbersin1Dspaceonanumberline.Vectoradditionisdefinedasthesumofthecomponentsoftwovectors,andcanbethoughtofastheresultingvectorifthetwocomponentvectorarrowsareplaced“tiptotail.”VectoradditionisperformedwiththeAddmethod,andisrepresentedbythediagramontheleft.a=Ve

45、ctor.ByCoordinates(5,5,0);b=Vector.ByCoordinates(4,1,0);/chasvaluex=9,y=6,z=0c=a.Add(b);Similarly,twoVectorobjectscanbesubtractedfromeachotherwiththeSubtractmethod.Vectorsubtractioncanbethoughtofasthedirectionfromfirstvectortothesecondvector.a=Vector.ByCoordinates(5,5,0);b=Vector.ByCoordinates(4,1,0

46、);/chasvaluex=1,y=4,z=0c=a.Subtract(b);Vectormultiplicationcanbethoughtofasmovingtheendpointofavectorinitsowndirectionbyagivenscalefactor.a=Vector.ByCoordinates(4,4,0);/chasvaluex=20,y=20,z=0c=a.Scale(5);Oftenitsdesiredwhenscalingavectortohavetheresultingvectorslengthexactlyequaltothescaledamount.Th

47、isiseasilyachievedbyfirstnormalizingavector,inotherwordssettingthevectorslengthexactlyequaltoone.a=Vector.ByCoordinates(1,2,3);a_len=a.Length;/settheaslengthequalto1.0b=a.Normalized();c=b.Scale(5);/lenisequalto5len=c.Length;cstillpointsinthesamedirectionasa(1,2,3),thoughnowithaslengthexactlyequalto5

48、.Twoadditionalmethodsexistinvectormathwhichdonthaveclearparallelswith1Dmath,thecrossproductanddotproduct.ThecrossproductisameansofgeneratingaVectorwhichisorthogonal(at90degreesto)totwoexistingVectors.Forexample,thecrossproductofthexandyaxesisthezaxis,thoughthetwoinputVectorsdontneedtobeorthogonaltoe

49、achother.AcrossproductvectoriscalculatedwiththeCrossmethod.a=Vector.ByCoordinates(1,0,1);b=Vector.ByCoordinates(0,1,1);/chasvaluex=-1,y=-1,z=1c=a.Cross(b);Anadditional,thoughsomewhatmoreadvancedfunctionofvectormathisthedotproduct.Thedotproductbetweentwovectorsisarealnumber(notaVectorobject)thatrelat

50、esto,butisnotexactly,theanglebetweentwovectors.Oneusefulpropertiesofthedotproductisthatthedotproductbetweentwovectorswillbe0ifandonlyiftheyareperpendicular.ThedotproductiscalculatedwiththeDotmethod.a=Vector.ByCoordinates(1,2,1);b=Vector.ByCoordinates(5,-8,4);/dhasvalue-7d=a.Dot(b);5:RangeExpressions

51、Almosteverydesigninvolvesrepetitiveelements,andexplicitlytypingoutthenamesandconstructorsofeveryPoint,Line,andotherprimitivesinascriptwouldbeprohibitivelytimeconsuming.RangeexpressionsgiveaDynamoprogrammerthemeanstoexpresssetsofvaluesasparametersoneithersideoftwodots(.),generatingintermediatenumbers

52、betweenthesetwoextremes.Forinstance,whilewehaveseenvariablescontainingasinglenumber,itispossiblewithrangeexpressionstohavevariableswhichcontainasetofnumbers.Thesimplestrangeexpressionfillsinthewholenumberincrementsbetweentherangestartandend.a=1.6;Inpreviousexamples,ifasinglenumberispassedinastheargu

53、mentofafunction,itwouldproduceasingleresult.Similarly,ifarangeofvaluesispassedinastheargumentofafunction,arangeofvaluesisreturned.Forinstance,ifwepassarangeofvaluesintotheLineconstructor,Dynamoreturnsarangeoflines.x_pos=1.6;y_pos=5;z_pos=1;lines=Line.ByStartPointEndPoint(Point.ByCoordinates(0,0,0),P

54、oint.ByCoordinates(x_pos,y_pos,z_pos);Bydefaultrangeexpressionsfillintherangebetweennumbersincrementingbywholedigitnumbers,whichcanbeusefulforaquicktopologicalsketch,butarelessappropriateforactualdesigns.Byaddingasecondellipsis(.)totherangeexpression,youcanspecifytheamounttherangeexpressionincrement

55、sbetweenvalues.Herewewantallthenumbersbetween0and1,incrementingby0.1:0了551.5a=;Oneproblemthatcanarisewhenspecifyingtheincrementbetweenrangeexpressionboundariesisthatthenumbersgeneratedwillnotalwaysfallonthefinalrangevalue.Forinstance,ifwecreatearangeexpressionbetween0and7,incrementingby0.75,t

56、hefollowingvaluesaregenerated:a=5;Ifadesignrequiresageneratedrangeexpressiontoendpreciselyonthemaximumrangeexpressionvalue,Dynamocanapproximateanincrement,comingascloseaspossiblewhilestillmaintaininganequaldistributionofnumbersbetweentherangeboundaries.Thisisdonewiththeapproximatesign()before

57、theIparameter:/DesignScriptwillincrementby0.777not0.75=5;-IList00.7777777777777781.555555555555562.333333333333333-111111111111113.88888888888889ever,ifyouwanttoDynamotointerpolatebetweenrangesadiscretenumberofelements,the#operatorallowsyoutoifythis:/Interpolatebetween0and7suchthat/“a”willcon

58、tain9elementsa=0.7.#9;6:CollectionsCollectionsarespecialtypesofvariableswhichholdsetsofvalues.Forinstance,acollectionmightcontainthevalues1to10,1,2,3,4,5,6,7,8,9,10,assortedgeometryfromtheresultofanIntersectionoperation,Surface,Point,Line,Point,orevenasetofcollectionsthemselves,1,2,3,4,5,6.Oneofthee

59、asierwaystogenerateacollectioniswithrangeexpressions(see:RangeExpressions).Rangeexpressionsbydefaultgeneratecollectionsofnumbers,thoughifthesecollectionsarepassedintofunctionsorconstructors,collectionsofobjectsarereturned./usearangeexpressiontogenerateacollectionof/numbersnums=5;/usethecolle

60、ctionofnumberstogeneratea/collectionofPointspoints=Point.ByCoordinates(nums,0,0);Whenrangeexpressionsarentappropriate,collectionscanbecreatedemptyandmanuallyfilledwithvalues.Thesquarebracketoperator()isusedtoaccessmembersinsideofacollection.Thesquarebracketsarewrittenafterthevariablesname,withthenum

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论