Be sure to read the Forum Rules and Guidelines before start using the Forum.
13/07/2018 at 18:41 #6721
I am trying to create a frame in python. However although it appears in the graphics window, I cant interact with it in anyway. It also doesnt appear in list of items under the root of the component. This code is directly copied from the help.Python12345678910111213141516171819202122232425from vcScript import *import vcMatrix as mtxapp = getApplication()comp = getComponent()#simple demo that clears geometry sets in root nodecomp.Geometry.clear()gs = comp.Geometry.createGeometrySet(VC_FRAMESET)#create full circle of framesdegrees = 360for i in xrange(degrees):gs.createFrame(mtx.new())gs.update()for i in xrange(gs.FrameCount):frame = gs.getFrame(i)frame.translateAbs(1000.0, 0.0, 0.0)frame.rotateAbsY(degrees)degrees = degrees - 1gs.setFrame(i, frame)gs.update()app.render()
You need to login in order to like this post: click here13/07/2018 at 19:22 #6723
Ok I figured this out.
You need to create a series of frames as features and type VC_FRAME under the root node and not a new geometry set of type VC_FRAMESETPython1framer = comp.RootFeature.createFeature(VC_FRAME,'frame')
You need to login in order to like this post: click here13/07/2018 at 20:24 #6724
although oddly it doesnt put the frame in the correct position until you turn the visibility on and off. I have tried turning it on and off in the code but it only does it when you manually click it on/off. Somehow the graphics screen does not update correctly.Python123456789101112131415161718192021222324from vcScript import *import vcMatrixmtx = vcMatrix.new()app = getApplication()comp = getComponent()gs = comp.Geometry.createGeometrySet(VC_FRAMESET)framer = comp.RootFeature.createFeature(VC_FRAME,'frame')geo_f = [x for x in comp.RootFeature.Children if x.Type == VC_FRAME]for f in geo_f:mtx = vcMatrix.new()mtx.translateRel(1000,500,500)f.PositionMatrix = mtxprint f.Name, f.PositionMatrix.P.X ,f.PositionMatrix.P.Y , f.PositionMatrix.P.Zf.Visible = FalsegetApplication().render()#f.Visible = TruegetApplication().render()getApplication().render()
You need to login in order to like this post: click here16/07/2018 at 08:54 #6745
The method .rebuild() does the same thing.Python1234mtx = vcMatrix.new()mtx.translateRel(1000,500,500)f.PositionMatrix = mtxf.rebuild()
You need to login in order to like this post: click here16/07/2018 at 12:25 #6749
In op, you are working at geometry set level not feature level. Frame feature is not the same thing as a Frame set.
Here is a video that explains the difference (link expires in 180 days)
You need to login in order to like this post: click here16/07/2018 at 17:42 #6755
Thanks for that great explanation.
Basically I am exporting frames from solid works to csv format.
Then importing them to visual components.
I have for the code working except it doesnt display the frames I have created until I do something else like run and reset the simulation or turn visibility on/off.
Here is my code….any ideas?Python123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051from vcScript import *import vcMatriximport csvimport os# create a new empty matrixmtx = vcMatrix.new()app = getApplication()comp = getComponent()# set the directory and filename to be importedos.chdir('c:\\temp')filename = "Dumb waiter v1.csv"with open(filename) as csvfile:readCSV = csv.reader(csvfile, delimiter=',')# read in the file into rows and then find the names and coordinatesfor row in readCSV:print rowframerNamer = rowx = float(row)y = float(row)z = float(row)rotX = float(row)rotY = float(row)rotZ = float(row)# create a new frame with the imported frame nameframer = comp.RootFeature.createFeature(VC_FRAME,framerNamer)# find the frame with the new imported name in the geometry setgeo_f = [j for j in comp.RootFeature.Children if j.Type == VC_FRAME]for f in geo_f:if f.Name == framerNamer:mtx = vcMatrix.new()# apply the rotations for the frame orientation around the world framemtx.rotateAbsX(rotX)mtx.rotateAbsY(rotY)mtx.rotateAbsZ(rotZ)# move the frame to its x y and z coordinates import from csvmtx.translateAbs(x,y,z)# rotate it around the world axis x = 90 degrees as solidworks uses Y# for verticalmtx.rotateAbsX(90)# apply the new matrix to the framef.PositionMatrix = mtx# rebuild the geometry so the frame appears in the right placef.rebuild()app.render()
You need to login in order to like this post: click here17/07/2018 at 12:58 #6765
Try a rebuild of the component, vcComponent.rebuild().
Here is a link (expires in 3 months) to a video where I show you a different approach using a vcLayoutSchemaPropertyList to create frames in the 3D world. In most cases, you only work with the schema object (define and edit it) using API — do not use the GUI.
If you ever use schema be aware of the following issues as of 4.1 release:
Frames might be recreated if you attach layout item to different node.
PositionMatrix property might not work at all.
Workaround would be to create schema property that defines offset.
Lines connecting frames might be buggy.
Issue with script parsing and complier, so consider using def OnFinalize() to safely generate the schema when loading layout.
So in the attached layout, I modifed the code I showed in the video to use the OnFinalize() event.
NB! Not sure if others are using 4.1, but a workaround for having a separate data.csv file would be to pack the file with the layout using the 4.1 pack folder feature, and then unpack it from auto-generated temp folder.
schema object – a vcLayoutSchemaPropertyList object
layout item – an object that exists in a layout, such as drawings, annotations, dimensions and bill of materials
Attachments:You must be logged in to view attached files.
You need to login in order to like this post: click here17/07/2018 at 14:46 #6770
seems to cure the visibility problem.
You need to login in order to like this post: click here17/07/2018 at 14:52 #6772
Another trick is sometimes to set or clear selection of the application’s selection manager.
You need to login in order to like this post: click here17/07/2018 at 15:39 #6777
I have run through you video and its handy to know.
However, for the purpose for which I was doing this was to have an lifter or conveyor modelled in another cad system parametrically. Then import the geometry to set up a basic component and then be able to update the paths inside with frames generated from Solid works in this case.
Therefore when the geometry gets translated for a larger or smaller model then it would be simple to update the paths.
In the schema method it seems that these cant be directly used with a path in a component due to the frames being in the layout rather than the component. well as far as I can tell anyway.
You need to login in order to like this post: click here17/07/2018 at 16:03 #6782
Understood. Yes, Frame features is the way to go. Schema frames are considered robot positions, so they cannot be referenced in Path behavior.
You need to login in order to like this post: click here18/07/2018 at 15:05 #6805
You shouldn’t need to use the vcSimulation.update(). That’s an overkill.
Rebuilding the frames and rendering should be enough. Like in the snippet below:Python123456789101112131415161718from vcScript import *import vcMatrixcomp = getComponent()app = getApplication()frames_trans = comp.RootFeature.createFeature(VC_TRANSFORM, 'Frames')frame1 = frames_trans.createFeature(VC_FRAME, 'F1')frame2 = frames_trans.createFeature(VC_FRAME, 'F2')mtx = vcMatrix.new()mtx.translateRel(200,300,400)mtx.rotateRelZ(45)frame1.PositionMatrix = mtxmtx.identity()mtx.translateRel(-200,300,400)mtx.rotateRelZ(-45)frame2.PositionMatrix = mtxframe1.rebuild()frame2.rebuild()app.render()
You need to login in order to like this post: click here
You must be logged in to reply to this topic.