revit open model

This commit is contained in:
sladro 2026-02-28 08:11:04 +08:00
parent b7e98af8ba
commit 1e4cdc55b7
4 changed files with 109 additions and 14 deletions

View File

@ -178,19 +178,40 @@ const handleOpenModel = async () => {
inputPlaceholder: '例如: Z:\\工具\\Revit2017(64bit)\\model.asm'
})
if (filePath && connectedCAD.id === 'creo') {
if (filePath) {
//
const processedFilePath = filePath.trim()
//
const openResult = await creoApi.openModelFile(processedFilePath)
if (openResult.success) {
//
const modelResult = await creoApi.getCurrentModel()
if (modelResult.success) {
cadStore.setCurrentProjectName(modelResult.data.data.fileName)
emit('show-model-viewer', modelResult.data)
if (connectedCAD.id === 'creo') {
//
const openResult = await creoApi.openModelFile(processedFilePath)
if (openResult.success) {
//
const modelResult = await creoApi.getCurrentModel()
if (modelResult.success) {
cadStore.setCurrentProjectName(modelResult.data.data.fileName)
emit('show-model-viewer', modelResult.data)
}
}
} else if (connectedCAD.id === 'revit') {
// Revit
const openResult = await revitApi.openModelFile(processedFilePath, false)
if (openResult.success) {
//
const modelResult = await revitApi.getCurrentModel()
if (modelResult.success) {
cadStore.setCurrentProjectName(modelResult.data.data.project.name)
emit('show-model-viewer', modelResult.data.data)
}
}
} else if (connectedCAD.id === 'pdms') {
ElNotification({
title: '暂不支持',
message: 'PDMS 打开模型文件功能尚未实现',
type: 'warning',
position: 'top-right',
duration: notificationConfig.ERROR_DURATION
})
}
}
} catch (error) {
@ -304,13 +325,52 @@ const handleDrop = async (event) => {
})
const openResult = await creoApi.openModelFile(filePath)
if (openResult.success) {
const modelResult = await creoApi.getCurrentModel()
if (modelResult.success) {
cadStore.setCurrentProjectName(modelResult.data.data.fileName)
emit('show-model-viewer', modelResult.data)
ElNotification({
title: '打开成功',
message: `已成功打开模型: ${fileName}`,
type: 'success',
position: 'top-right',
duration: notificationConfig.SUCCESS_DURATION
})
}
} else {
throw new Error(openResult.error || 'API返回失败')
}
} catch (error) {
ElNotification({
title: '打开失败',
message: error.message || '未知错误',
type: 'error',
position: 'top-right',
duration: notificationConfig.ERROR_DURATION
})
}
} else if (connectedCAD.id === 'revit') {
// Revit
try {
ElNotification({
title: '正在打开',
message: `正在请求Revit打开: ${fileName}`,
type: 'info',
position: 'top-right',
duration: 2000
})
const openResult = await revitApi.openModelFile(filePath, false)
if (openResult.success) {
const modelResult = await revitApi.getCurrentModel()
if (modelResult.success) {
cadStore.setCurrentProjectName(modelResult.data.data.project.name)
emit('show-model-viewer', modelResult.data.data)
ElNotification({
title: '打开成功',
message: `已成功打开模型: ${fileName}`,

View File

@ -352,6 +352,7 @@ import { websocketService } from '@/services/websocketService'
import { getWebSocketConfig } from '@/config/cad'
import { useCADStore } from '@/stores/cad'
import creoApi from '@/services/creoApi'
import revitApi from '@/services/revitApi'
const cadStore = useCADStore()
@ -835,9 +836,22 @@ const openModel = async (fileInfo) => {
console.error('调用Creo打开接口异常', error)
alert(`打开模型失败: ${error.message}`)
}
} else if (currentCADId === 'revit') {
// Revit: API
try {
const result = await revitApi.openModelFile(fileInfo.filePath, false)
if (result && result.success) {
console.log(`Revit打开模型成功: ${fileInfo.filename}`)
} else {
console.error('Revit打开模型失败', result)
}
} catch (error) {
console.error('调用Revit打开接口异常', error)
alert(`打开模型失败: ${error.message}`)
}
} else {
// 3. :
alert(`当前连接的是 ${cadStore.currentCAD.name}该软件的打开模型接口尚未实现仅支持Creo`)
alert(`当前连接的是 ${cadStore.currentCAD.name}该软件的打开模型接口尚未实现仅支持Creo和Revit)。`)
}
}

View File

@ -106,14 +106,15 @@ const CAD_SOFTWARE_DEFINITIONS = {
apiVersion: 'v1',
priority: 2,
description: 'BIM模型管理',
features: ['overview', 'shellAnalysis', 'exportIfc'],
features: ['overview', 'shellAnalysis', 'exportIfc', 'open'],
endpoints: {
connect: '/api/health',
overview: '/api/overview',
shellAnalysis: '/api/shell/analyze',
exportIfc: '/api/export/ifc',
shellExecute: '/api/shell/execute',
taskStatus: '/api/task'
taskStatus: '/api/task',
open: '/api/open'
}
},
PDMS: {

View File

@ -130,6 +130,26 @@ class RevitApiService {
}
})
}
/**
* 打开模型文件
* @param {string} filePath - 模型文件绝对路径
* @param {boolean} detached - 是否分离打开默认false
* @returns {Promise<{success: boolean, data?: any, error?: string}>}
*/
async openModelFile(filePath, detached = false) {
const url = buildApiUrl(this.softwareName, 'open')
return await apiClient.post(url, {
filePath,
detached
}, {
operationContext: {
software: 'Revit',
operation: '打开模型文件'
}
})
}
}
// 导出单例实例