gpt4 book ai didi

excel - 如何在 Excel 中绘制 3D 线框?

转载 作者:行者123 更新时间:2023-12-04 22:21:50 25 4
gpt4 key购买 nike

使用 Excel 界面,如何绘制 3D 线框?我不知道该怎么做!但想通过给出它们之间有框架的关节的坐标来做到这一点。

为简单起见,只需想象一个立方体形式的 3D 线框。

enter image description here

最佳答案

好的,所以我之前给出了打开宏记录器的建议,但这不会为您提供绘制线框所需的 3D 数学。为此,您需要一个库,Philip Rideout's SVG wireframes Python library这是written up here on his blog .

my blog I have added some code which parses the SVG file由 Philip Rideout 的代码生成,然后将 Polygon 指令从工作表上的形状转换为 Excel。这是输出的屏幕截图。

3D wireframe on an Excel worksheet

我也在这里添加了代码

class ScreenUpdatingRAII(object):
def __init__(self, app, visible:bool=False):
self.app = app
self.saved = app.ScreenUpdating
app.ScreenUpdating = visible

def restore(self):
self.app.ScreenUpdating = self.saved
self.app = None


def convertSvgToExcelShapes(filename):
import xml.etree.ElementTree as ET
from win32com.client import GetObject,Dispatch

# code below is highly dependent on the child
# structure because xpath was not working for me (my bad)
dom = ET.parse(filename)
rootxml = dom.getroot()
g = rootxml[1] # second child
wb = Dispatch(GetObject(r"C:\Users\Simon\source\repos\WireframeExcelShapes\WireframeExcelShapes\WireframeExcelShapes.xlsx"))
app = Dispatch(wb.Parent)
ws = Dispatch(wb.Worksheets.Item("WireFrame"))

shps = Dispatch(ws.Shapes)

for x in shps:
Dispatch(x).Delete()
idx =0
scale, xoffset, yoffset = 500, 300,300

screenUpdates = ScreenUpdatingRAII(app)

for polygon in g:

# triple nested list comprehension parsing the points by splitting
# first by space then by comma then converting to float
points = [[float(z[0])*scale+xoffset, float(z[1])*scale+yoffset] for z in [y.split(',') for y in [x for x in polygon.attrib['points'].split()]]]

#print(points)
msoEditingAuto,msoSegmentLine, msoFalse, msoTrue = 0,0,0, -1

freeformbuilder=shps.BuildFreeform(msoEditingAuto, points[0][0] , points[0][1])
freeformbuilder.AddNodes(msoSegmentLine, msoEditingAuto, points[1][0] , points[1][1])
freeformbuilder.AddNodes(msoSegmentLine, msoEditingAuto, points[2][0] , points[2][1])
freeformbuilder.AddNodes(msoSegmentLine, msoEditingAuto, points[0][0], points[0][1])
newShp = Dispatch(freeformbuilder.ConvertToShape())

shpFill = Dispatch(newShp.Fill)

shpFill.Visible = msoTrue
shpFill.Transparency = 0.25
shpFill.Solid
shpFill.ForeColor.RGB = 0xFFFFFF
idx=+1

screenUpdates.restore()
pass



filename = "octahedron.svg"
generate_svg(filename)
convertSvgToExcelShapes(filename)

由于示例形状是八面体,您仍然需要做一些工作来生成自己的形状。

关于excel - 如何在 Excel 中绘制 3D 线框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62249112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com