richg1
Mechanical
- Sep 25, 2002
- 77
Hi,
Supposedly in Ansys 12 there's going to be new functionality to more easily allow the export of deformed geometry. But in the mean time here's a method of exporting STL based data from Workbench.
I can't claim any credit for the original STL export script (ie. the difficult bit), that was courtesy of 'Dave Lindeman' on xansys circa 2001. Thanks Dave if you're out there.
Just make sure your 'Save Ansys db' in the workbench analysis settings is set to 'Yes'. I've also disabled the scaling function so the output size is per the model.
I'm sure it's got some bugs and I haven't tried it on a big model but it has worked for me so far, allowing us to take deformed data into our raytracing software...Rich
******************
! Commands inserted into this file will be executed immediately after the Ansys /POST1 command.
! Active UNIT system in Workbench when this object was created: Metric (mm, kg, N, C, s, mV, mA)
! Below is an APDL script I've used to generate STL files. This version assumes the exterior of the solid has been meshed with MESH200 elements (quad/tris). Shell elements would also work.
! Note that you could modify the script so that it loops through the element faces associated with the exterior nodes, but it's easier to just ESURF some elements onto the exterior.
! Also, you could add the displacements to the nodal coordinates before writing out the vertex definitions if you want the deformed geometry.
! LENG is the actual, characteristic dimension of the prototpye you would like to create (in inches, meters, etc.)
! This can be used to scale the size of the model up or down (so you can prototype really big MEMS devices, or really little offshore oil platforms). (Dave Lindeman)
! Command object to save the database
/COPY,file,rst,,update,rst,
/COPY,file,db,,update,db,
resu,update,db
file,update,rst
fini
/prep7
/show,png
/gfile,500
!/edge,1,1
/view,1,1,1,1
/title, Element Plot before Updating
eplot
UPGEOM,1,1,1,'update','rst',
/title, Element Plot After Updating
eplot
/title, nodes Plot After Updating
nplot
/prep7
CMSEL,S,ObjectFace ! named selection from WB
/view,1,1,1,1
/title, selected the nodal component created by Nodal_component named Selection
NPLOT
ESLN,S
/title, Plotting the elements attached to the selected nodal component
EPLOT
CSYS,0
*GET,XMIN,NODE,,MNLOC,X
*GET,XMAX,NODE,,MXLOC,X
*GET,YMIN,NODE,,MNLOC,Y
*GET,YMAX,NODE,,MXLOC,Y
*GET,ZMIN,NODE,,MNLOC,Z
*GET,ZMAX,NODE,,MXLOC,Z
LENG = 100 ! Used in SCLE
MXLN = (XMAX-XMIN)>(YMAX-YMIN)>(ZMAX-ZMIN)
!SCLE = LENG/MXLN ! Original Command to scale output to LENG
SCLE = 1 ! Scale set to 1 to get STL file same as model size
/NOPR
*CFOPEN,C:\Temp\ObjectFace,stl ! output filename - make sure you have a c:\temp directory
*VWRITE
('solid ANSYS')
*GET,NELE,ELEM,,COUNT
*DIM,N,ARRAY,4
*DIM,E,ARRAY,NELE,3
ENUM = 0
NQUA = 0
*DO,I,1,NELE,1
ENUM = ELNEXT(ENUM)
*DO,J,1,4,1
N(J) = NELEM(ENUM,J)
*ENDDO
*IF,N(4),NE,N(3),THEN
NQUA = NQUA+1
E(NQUA,1) = N(1)
E(NQUA,2) = N(3)
E(NQUA,3) = N(4)
*ENDIF
NX = NORMNX(N(1),N(2),N(3))
NY = NORMNY(N(1),N(2),N(3))
NZ = NORMNZ(N(1),N(2),N(3))
*VWRITE,NX,NY,NZ
('facet normal',3(2X,E16.9))
*VWRITE
('outer loop')
*DO,J,1,3,1
*VWRITE,SCLE*NX(N(J)),SCLE*NY(N(J)),SCLE*NZ(N(J))
('vertex',3(2X,E16.9))
*ENDDO
*VWRITE
('endloop')
*VWRITE
('endfacet')
*ENDDO
*DO,I,1,NQUA,1
NX = NORMNX(E(I,1),E(I,2),E(I,3))
NY = NORMNY(E(I,1),E(I,2),E(I,3))
NZ = NORMNZ(E(I,1),E(I,2),E(I,3))
*VWRITE,NX,NY,NZ
('facet normal',3(2X,E16.9))
*VWRITE
('outer loop')
*DO,J,1,3,1
*VWRITE,SCLE*NX(E(I,J)),SCLE*NY(E(I,J)),SCLE*NZ(E(I,J))
('vertex',3(2X,E16.9))
*ENDDO
*VWRITE
('endloop')
*VWRITE
('endfacet')
*ENDDO
*VWRITE
('endsolid ANSYS')
*CFCLOS
/GOPR
******************
Supposedly in Ansys 12 there's going to be new functionality to more easily allow the export of deformed geometry. But in the mean time here's a method of exporting STL based data from Workbench.
I can't claim any credit for the original STL export script (ie. the difficult bit), that was courtesy of 'Dave Lindeman' on xansys circa 2001. Thanks Dave if you're out there.
Just make sure your 'Save Ansys db' in the workbench analysis settings is set to 'Yes'. I've also disabled the scaling function so the output size is per the model.
I'm sure it's got some bugs and I haven't tried it on a big model but it has worked for me so far, allowing us to take deformed data into our raytracing software...Rich
******************
! Commands inserted into this file will be executed immediately after the Ansys /POST1 command.
! Active UNIT system in Workbench when this object was created: Metric (mm, kg, N, C, s, mV, mA)
! Below is an APDL script I've used to generate STL files. This version assumes the exterior of the solid has been meshed with MESH200 elements (quad/tris). Shell elements would also work.
! Note that you could modify the script so that it loops through the element faces associated with the exterior nodes, but it's easier to just ESURF some elements onto the exterior.
! Also, you could add the displacements to the nodal coordinates before writing out the vertex definitions if you want the deformed geometry.
! LENG is the actual, characteristic dimension of the prototpye you would like to create (in inches, meters, etc.)
! This can be used to scale the size of the model up or down (so you can prototype really big MEMS devices, or really little offshore oil platforms). (Dave Lindeman)
! Command object to save the database
/COPY,file,rst,,update,rst,
/COPY,file,db,,update,db,
resu,update,db
file,update,rst
fini
/prep7
/show,png
/gfile,500
!/edge,1,1
/view,1,1,1,1
/title, Element Plot before Updating
eplot
UPGEOM,1,1,1,'update','rst',
/title, Element Plot After Updating
eplot
/title, nodes Plot After Updating
nplot
/prep7
CMSEL,S,ObjectFace ! named selection from WB
/view,1,1,1,1
/title, selected the nodal component created by Nodal_component named Selection
NPLOT
ESLN,S
/title, Plotting the elements attached to the selected nodal component
EPLOT
CSYS,0
*GET,XMIN,NODE,,MNLOC,X
*GET,XMAX,NODE,,MXLOC,X
*GET,YMIN,NODE,,MNLOC,Y
*GET,YMAX,NODE,,MXLOC,Y
*GET,ZMIN,NODE,,MNLOC,Z
*GET,ZMAX,NODE,,MXLOC,Z
LENG = 100 ! Used in SCLE
MXLN = (XMAX-XMIN)>(YMAX-YMIN)>(ZMAX-ZMIN)
!SCLE = LENG/MXLN ! Original Command to scale output to LENG
SCLE = 1 ! Scale set to 1 to get STL file same as model size
/NOPR
*CFOPEN,C:\Temp\ObjectFace,stl ! output filename - make sure you have a c:\temp directory
*VWRITE
('solid ANSYS')
*GET,NELE,ELEM,,COUNT
*DIM,N,ARRAY,4
*DIM,E,ARRAY,NELE,3
ENUM = 0
NQUA = 0
*DO,I,1,NELE,1
ENUM = ELNEXT(ENUM)
*DO,J,1,4,1
N(J) = NELEM(ENUM,J)
*ENDDO
*IF,N(4),NE,N(3),THEN
NQUA = NQUA+1
E(NQUA,1) = N(1)
E(NQUA,2) = N(3)
E(NQUA,3) = N(4)
*ENDIF
NX = NORMNX(N(1),N(2),N(3))
NY = NORMNY(N(1),N(2),N(3))
NZ = NORMNZ(N(1),N(2),N(3))
*VWRITE,NX,NY,NZ
('facet normal',3(2X,E16.9))
*VWRITE
('outer loop')
*DO,J,1,3,1
*VWRITE,SCLE*NX(N(J)),SCLE*NY(N(J)),SCLE*NZ(N(J))
('vertex',3(2X,E16.9))
*ENDDO
*VWRITE
('endloop')
*VWRITE
('endfacet')
*ENDDO
*DO,I,1,NQUA,1
NX = NORMNX(E(I,1),E(I,2),E(I,3))
NY = NORMNY(E(I,1),E(I,2),E(I,3))
NZ = NORMNZ(E(I,1),E(I,2),E(I,3))
*VWRITE,NX,NY,NZ
('facet normal',3(2X,E16.9))
*VWRITE
('outer loop')
*DO,J,1,3,1
*VWRITE,SCLE*NX(E(I,J)),SCLE*NY(E(I,J)),SCLE*NZ(E(I,J))
('vertex',3(2X,E16.9))
*ENDDO
*VWRITE
('endloop')
*VWRITE
('endfacet')
*ENDDO
*VWRITE
('endsolid ANSYS')
*CFCLOS
/GOPR
******************