enzym Posted November 21, 2011 Share Posted November 21, 2011 (edited) Dear Od, I am doing something that's a little bit experimental. Basically I would like to import point data from outside into Houdini. The format is simple Unicode as below: //=========================================================================== // Script data follows: //=========================================================================== <Events> <StrokeEvent> <StrokeHeader> <EventPt> Wait: 0.000s Loc: (369, 196) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO </EventPt> <Recorded> Yes </Recorded> <RandSeed> 0x000000000, 0x000000000 </RandSeed> <Smooth> Count: 3 Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 </Smooth> <PrevA> Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 </PrevA> <PrevB> Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 </PrevB> <OldHd> Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 Dr: (0, 0) Hd: (0, 0) </OldHd> <NewHd> Loc: (0, 0) Pr: 0 Ti: 1 Ro: 0 Dr: (0, 0) Hd: (0, 0) </NewHd> </StrokeHeader> Wait: 0.000s Loc: (372, 195) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.031s Loc: (376, 194) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (383, 192) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.022s Loc: (389.5, 190) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.028s Loc: (399.25, 186.5) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.030s Loc: (411.625, 182.25) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (425.312, 177.625) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (440.656, 172.312) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.018s Loc: (452.328, 168.156) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.030s Loc: (467.164, 163.078) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (482.082, 157.539) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (496.541, 152.27) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (510.771, 147.135) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (523.885, 142.567) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (535.943, 137.784) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (547.471, 132.392) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (556.736, 128.196) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (563.868, 124.598) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (568.934, 122.299) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.064s Loc: (571.467, 120.649) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.128s Loc: (572.733, 120.325) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.064s Loc: (573.367, 122.662) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (571.683, 126.331) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (569.342, 133.166) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (565.171, 142.583) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (560.085, 154.291) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (554.543, 168.646) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (548.271, 183.823) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (542.136, 200.411) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (536.568, 216.706) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (531.284, 233.853) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.031s Loc: (526.142, 252.426) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.033s Loc: (521.071, 272.713) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (516.036, 292.357) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (511.518, 311.178) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (507.759, 330.089) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (504.379, 349.045) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (500.69, 368.522) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (497.345, 385.261) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (494.672, 401.631) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (491.336, 416.315) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (488.668, 428.658) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (486.334, 438.329) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (484.667, 445.164) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (483.833, 449.582) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.080s Loc: (482.917, 452.291) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.031s Loc: (478, 456) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO </StrokeEvent> <StrokeEvent> <StrokeHeader> <EventPt> Wait: 1.937s Loc: (455, 293) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO </EventPt> <Recorded> Yes </Recorded> <RandSeed> 0x000000001, 0x000000000 </RandSeed> <Smooth> Count: 3 Loc: (483.866, 448.055) Pr: 1 Ti: 1 Ro: -0.75 Loc: (481.596, 451.561) Pr: 1 Ti: 1 Ro: -0.75 Loc: (479.327, 455.068) Pr: 1 Ti: 1 Ro: -0.75 </Smooth> <PrevA> Loc: (482.917, 452.291) Pr: 1 Ti: 1 Ro: -0.75 </PrevA> <PrevB> Loc: (483.833, 449.582) Pr: 1 Ti: 1 Ro: -0.75 </PrevB> <OldHd> Loc: (481.596, 451.561) Pr: 1 Ti: 1 Ro: -0.75 Dr: (-0.249038, 0.968494) Hd: (-0.968494, -0.249038) </OldHd> <NewHd> Loc: (479.327, 455.068) Pr: 1 Ti: 1 Ro: -0.75 Dr: (-0.249038, 0.968494) Hd: (-0.968494, -0.249038) </NewHd> </StrokeHeader> Wait: 0.000s Loc: (463.5, 292) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (480.25, 288.5) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (501.625, 284.75) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (525.312, 280.375) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.032s Loc: (546.656, 276.188) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.033s Loc: (565.328, 273.594) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.031s Loc: (581.664, 272.297) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO Wait: 0.017s Loc: (599, 272) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO </StrokeEvent> //=========================================================================== // End of Script //=========================================================================== That script is actually recorded and generated by this app "ArtRage" for iPad that allow for ArtRage on desktop to be read back. Their script documentation is as below: http://www.artrage.com/files/artrage_advancedscriptingguide.pdf Actually for my case, I just need Houdini to read back the Loc: (X, Y) and connect them as curve, if it is within 1 Stroke Event. My question is: How to import point data like above Loc: (X, Y) into Houdini? I supposed this script is really simple to import using Python? I will check for Houdini python documentation also maybe it could lead to some solution. Thank you. - Jimmy Edited November 21, 2011 by enzym Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted November 21, 2011 Share Posted November 21, 2011 Yes Python sounds like a nice solution. I would make a Python SOP with a fancy regexp to only grab the 'Loc:' from the file and then create points. I might be back with some file later when I am home from work if no one else haven't already made it. Quote Link to comment Share on other sites More sharing options...
Green-Man Posted November 21, 2011 Share Posted November 21, 2011 It's really not a straightforward list of coordinates I think. There are several types of Loc: () in such kind of a structure. And it may happen that some coordinates (<PrevA>,<PrevB>) we should use not like a simple X,Y. But its just the details. And you probably lost </Events> at the end of the // End of Script. Its necessary for properly parsing this XML. This is a sample code for parsing XML with elementtree and parsing strings with re. These modules are standard for python (and hython:) It creates primitives with points just with the coordinates that stores inside a <StrokeEvent></StrokeEvent> and tail of <StrokeHeader>. Points of <EventPt>, <Smooth>, <PrevA> and <PrevB> are ignored. But its not so difficult task to modify this code for this purpose import re import _elementtree as ET filename = "code.txt" #Path to the file file = open(filename, 'r') #Rule for splitting long string like Wait: 0.000s Loc: (372, 195) Pr: 1 Ti: 1 Ro: -0.75 Rv: NO Iv: NO #with round brackets mainrule = re.compile(r'([()])') #Rule for splitting coordinates pair by commas. commarule = re.compile(r'([,])') coords =[] geo = hou.pwd().geometry() #Parsing XML and generating arrays of coordinates for every <StrokeEvent> tree = ET.parse(filename) root = tree.getroot() for event in root: curvelength = 0 coords = [] for header in event: list = mainrule.split(header.tail) for i,item in zip(range(len(list)), list): if item.endswith("Loc: "): x = commarule.split(list[i+2])[0] y = commarule.split(list[i+2])[2] coords.append([float(x),float(y),0]) #Creating geometry itself pointarray = geo.createPolygon() for p in coords: point = geo.createPoint() point.setPosition(p) pointarray.addVertex(point) #It will help to get other the points from the other elements # for subitem in header: # print "-> Item = "+subitem.tag # print subitem.text Quote Link to comment Share on other sites More sharing options...
enzym Posted November 30, 2011 Author Share Posted November 30, 2011 Hmmmm... that seems to be more complicated that I thought. I will keep this reference for in the future when I understand Python better. Thanks for all the responses. -J Quote Link to comment Share on other sites More sharing options...
enzym Posted December 2, 2011 Author Share Posted December 2, 2011 I found the answer in other post. It sort of leading the right direction. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.