找回密码
 注册
Simdroid-非首页
查看: 174|回复: 11

[二次开发] UG 二维工程图转PDF文件(已结贴,采用VB开发)

[复制链接]
发表于 2009-5-14 00:11:08 | 显示全部楼层 |阅读模式 来自 河北邢台
悬赏1仿真币未解决
本帖最后由 lirui0726 于 2009-6-13 16:31 编辑

条件:自动化程序实现 ug/open,batch模式运行,不用控件
           悬赏期限15天

另加2技术积分!

发表于 2009-5-14 07:36:08 | 显示全部楼层 来自 辽宁大连
Simdroid开发平台
二次开发我就闪一边去了,呵呵,不懂
lirui兄,我把你的内容稍微编辑了一下,十个技术积分太太多了,这是simwe有史以来可能没有的,simwe的技术积分比较难拿。
回复

使用道具 举报

发表于 2009-5-14 07:56:57 | 显示全部楼层 来自 浙江杭州
google了一下,好像能搜到相关的帖子啊,原来我试过找API直接显示出来打印的界面,没成功,后来找了个函数直接打印是可以的,你这个弄pdf不知道是不是用一些.net的控件可不可以实现,应该是可以的吧

评分

1

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2009-5-14 23:57:28 | 显示全部楼层 来自 河北邢台
本帖最后由 lirui0726 于 2009-5-15 00:01 编辑

呵呵,不用控件,BATCH运行模式
看高兄出手咯!
回复

使用道具 举报

 楼主| 发表于 2009-5-14 23:59:27 | 显示全部楼层 来自 河北邢台
大家加油哦,我自己已经有头绪了
回复

使用道具 举报

发表于 2009-5-15 09:51:28 | 显示全部楼层 来自 辽宁大连
恩,加油
回复

使用道具 举报

发表于 2009-5-15 22:56:35 | 显示全部楼层 来自 河北廊坊
不知楼主是否已经解决?如果解决了,或者是有了比较好的思路是否可以贴出来,供大家学习一下了。

评分

1

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2009-5-19 22:48:04 | 显示全部楼层 来自 湖北武汉
呵呵,悬赏结贴了。
过几天我会把答案贴处理
回复

使用道具 举报

 楼主| 发表于 2009-6-13 16:30:37 | 显示全部楼层 来自 山西太原
export pdf of each drawing sheet in each part in specified directory

Build this as an executable NXOpen .NET Console Application
' and run it like this:
'
' batch_export_pdf.exe  D:\Full\Path\To\NXPartFiles
'
' Or, you can use run_journal.exe to run it like this:
'
' run_journal   batch_export_pdf.vb   -args  D:\Your\Full\Path\To\NXPartFiles
'
' (Both cases above assume that you save this file as "batch_export_pdf.vb")
'
'
' Note that while it screens for files whose names end in '.prt', it does
' not check all possible upper- and lower- case combinations.  Also,
' if the directory contains files that have a .prt extension, and that
' are NOT NX part files, an error will result.
'
' Note that the export options in this example program MAY NOT represent the
' options that you would have chosen.  You may change this as required to use
' any valid options.  See the NXOpen for .Net Reference Guide for details.

Option Strict Off
Imports System
Imports System.Collections

Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UF
Imports NXOpen.Utilities

Module export_pdf_of_each_drawing_sheet_in_each_part_in_specified_directory

    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow

    Sub Main(ByVal args As String())

        '
        'Uncomment the following line and use your actual load options filespec
        'including the entire path and the filename.
        '
        'ufs.Assem.RestoreLoadOptions("D:\Path\To\Your\load_options.def")


        Try

            Dim theDirectory As String = args(0)
            '
            'NOTE:  If you want to run this from Tools->Journal->Play, then
            'comment the line above and specify the directory as shown
            'on the following commented line:
            '
            'Dim theDirectory As String = "D:\Path\to\your\part\files"

            lw.Open()
            lw.WriteLine(" ")
            lw.WriteLine("Directory to process: " & theDirectory)
            lw.WriteLine(" ")

            Dim partFlag As Integer = 0
            Dim partCount As Integer = 0
            For Each fileName As String In My.Computer.FileSystem.GetFiles( _
                                                                 theDirectory)
                Dim extension As String = Right$(fileName, 4)

                If extension = ".prt" Or _
                   extension = ".PRT" Or _
                   extension = ".Prt" Then
                    partFlag = open_part_file(fileName)
                    partCount = ufs.Part.AskNumParts()
                End If

                If partFlag > 0 Then
                    ' Some parts failed to open.
                    ' Take appropriate action here
                    '-----------------------------
                Else
                    If partCount > 0 Then

                        process_each_drawing(s.Parts.Display(), fileName)

                    End If
                End If

                ' Close any open part files


                If partCount > 0 Then

                    s.Parts.CloseAll(BasePart.CloseModified.CloseModified, _
                                                                     Nothing)
                    lw.WriteLine("  ")

                End If
                ufs.Undo.DeleteAllMarks()

            Next

        Catch ex As Exception
            Console.OpenStandardOutput()
            Console.WriteLine(ex.ToString)
            Console.WriteLine()
        End Try

    End Sub

    Sub process_each_drawing(ByVal thePart As Part, ByVal fileName As String)

        If thePart.Tag = Tag.Null Then
            Return
        End If

        Dim drawingSheets As DrawingSheet() = thePart.DrawingSheets.ToArray

        If drawingSheets.Length() > 0 Then
            lw.WriteLine("    Sheets found: " & drawingSheets.Length().ToString())
        End If

        Dim mySheet As DrawingSheet = Nothing

        Dim partName As String = thePart.Leaf.ToString()

        For Each mySheet In drawingSheets

            lw.WriteLine("        Processing Sheet: " & mySheet.Name())

            mySheet.Open()

            s.Parts.Work.DraftingViews.UpdateViews( _
                           DraftingViewCollection.ViewUpdateOption.All, mySheet)

            Dim pdf_output_name As String = ""
            pdf_output_name = fileName.ToLower()
            pdf_output_name = pdf_output_name.Replace(".prt", "")
            Dim sheetName As String = mySheet.Name.ToLower()
            pdf_output_name = String.Concat(pdf_output_name, "_", sheetName, ".PDF")
            lw.WriteLine("PDF: " & pdf_output_name)

            Dim workPart As Part = s.Parts.Work()

            Dim printPDFBuilder1 As PrintPDFBuilder
            printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()

            Dim dwgUnits As DrawingSheet.Unit = mySheet.Units

            If dwgUnits = DrawingSheet.Unit.Inches Then
                printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
            End If

            If dwgUnits = DrawingSheet.Unit.Millimeters Then
                printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric
            End If

            printPDFBuilder1.Scale = 1.0
            printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.New
            printPDFBuilder1.Colors = PrintPDFBuilder.Color.AsDisplayed
            printPDFBuilder1.Widths = PrintPDFBuilder.Width.StandardWidths
            printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor
            printPDFBuilder1.XDimension = mySheet.Length()
            printPDFBuilder1.YDimension = mySheet.Height()
            printPDFBuilder1.RasterImages = True
            printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.High
            printPDFBuilder1.ShadedGeometry = True
            Dim sheets1(0) As NXObject

            sheets1(0) = mySheet
            printPDFBuilder1.SourceBuilder.SetSheets(sheets1)

            printPDFBuilder1.Filename = pdf_output_name

            Dim nXObject1 As NXObject
            nXObject1 = printPDFBuilder1.Commit()

            printPDFBuilder1.Destroy()

        Next

    End Sub

    Public Function open_part_file(ByVal fileName As String) As Integer

        Dim loadStatus As NXOpen.PartLoadStatus = Nothing

        Dim currentPart As Part = _
             s.Parts.OpenBaseDisplay(fileName, loadStatus)
        If loadStatus.NumberUnloadedParts < 1 Then
            lw.WriteLine("   Processing Part File: " & fileName)

        Else

            For inx As Integer = 0 To loadStatus.NumberUnloadedParts - 1
                lw.WriteLine(loadStatus.GetStatus(inx).ToString())
                Dim errno As Integer = CInt(loadStatus.GetStatus(inx))
                Dim errmsg As String = ""

                ufs.UF.GetFailMessage(errno, errmsg)

                lw.WriteLine("Error: " & errmsg & " in: " & fileName)
                lw.WriteLine("  ")
            Next

        End If

        Return loadStatus.NumberUnloadedParts()

    End Function
End Module
回复

使用道具 举报

发表于 2009-6-15 12:20:42 | 显示全部楼层 来自 黑龙江牡丹江
等待学习,希望高手指点
回复

使用道具 举报

发表于 2009-6-15 16:22:30 | 显示全部楼层 来自 上海
thanks a lots
回复

使用道具 举报

发表于 2010-9-1 17:14:55 | 显示全部楼层 来自 湖南长沙
牛啊,很想达到这样的水平
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-20 08:54 , Processed in 0.048786 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表