ciach
Mechanical
- Sep 23, 2011
- 19
Hi guys,
I'm looking for NX Api function to add image into drafting sheet. Any idea?
I'm looking for NX Api function to add image into drafting sheet. Any idea?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=green]'eng-tips thread561-335144[/color]
[COLOR=green]'import image to drafting sheet[/color]
[COLOR=blue]Option Strict Off[/color]
[COLOR=blue]Imports[/color] System
[COLOR=blue]Imports[/color] NXOpen
[COLOR=blue]Imports[/color] NXOpen.UF
[COLOR=blue]Module[/color] Module1
[COLOR=blue]Sub[/color] Main()
[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work
[COLOR=blue]Dim[/color] imageFile [COLOR=blue]As String =[/color] "C:\temp\test.jpg"
[COLOR=blue]Dim[/color] sheetTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null
[COLOR=blue]Dim[/color] imageCoordinates(2) [COLOR=blue]As Double[/color]
imageCoordinates(0) [COLOR=blue]=[/color] 0
imageCoordinates(1) [COLOR=blue]=[/color] 0
imageCoordinates(2) [COLOR=blue]=[/color] 0
[COLOR=blue]Dim[/color] imageTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null
ufs.Drf.CreateImageFromFile(imageFile, sheetTag, imageCoordinates, imageTag)
[COLOR=blue]If[/color] imageTag.Equals(Tag.Null) [COLOR=blue]Then[/color]
[COLOR=green]'image was not imported[/color]
End [COLOR=blue]If[/color]
End [COLOR=blue]Sub[/color]
[COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As Integer[/color]
[COLOR=green]'Unloads the image when the NX session terminates[/color]
GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination
End [COLOR=blue]Function[/color]
End [COLOR=blue]Module[/color]
[COLOR=blue]Option Strict Off[/color]
[COLOR=blue]Imports[/color] System
[COLOR=blue]Imports[/color] NXOpen
[COLOR=blue]Imports[/color] NXOpen.UF
[COLOR=blue]Module[/color] Module1
[COLOR=blue]Sub[/color] Main()
[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work
[COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow
lw.Open()
[COLOR=blue]Dim[/color] imageFile [COLOR=blue]As String =[/color] "C:\temp\test.jpg"
[COLOR=blue]Dim[/color] sheetTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null
[COLOR=blue]Dim[/color] imageCoordinates(2) [COLOR=blue]As Double[/color]
imageCoordinates(0) [COLOR=blue]=[/color] 0
imageCoordinates(1) [COLOR=blue]=[/color] 0
imageCoordinates(2) [COLOR=blue]=[/color] 0
[COLOR=blue]Dim[/color] imageTag [COLOR=blue]As[/color] Tag [COLOR=blue]=[/color] Tag.Null
[COLOR=blue]Dim[/color] myImageData [COLOR=blue]As[/color] UFDrf.ImageData
ufs.Drf.CreateImageFromFile(imageFile, sheetTag, imageCoordinates, imageTag)
[COLOR=blue]If[/color] imageTag.Equals(Tag.Null) [COLOR=blue]Then[/color]
[COLOR=green]'image was not imported[/color]
[COLOR=blue]Else[/color]
ufs.Drf.AskImageData(imageTag, myImageData)
lw.WriteLine("initial settings")
lw.WriteLine("original image height: " [COLOR=blue]&[/color] myImageData.height.ToString)
lw.WriteLine("original image width: " [COLOR=blue]&[/color] myImageData.width.ToString)
lw.WriteLine("aspect ratio locked: " [COLOR=blue]&[/color] myImageData.aspect_ratio_locked.ToString)
lw.WriteLine("name: " [COLOR=blue]&[/color] myImageData.image_name)
lw.WriteLine("")
[COLOR=green]'lock the aspect ratio[/color]
ufs.Drf.SetImageAspectRatioLock(imageTag, [COLOR=blue]True[/color])
[COLOR=green]'resize width to be 1/2 original width[/color]
ufs.Drf.SetImageWidth(imageTag, myImageData.width [COLOR=blue]/[/color] 2)
End [COLOR=blue]If[/color]
lw.Close()
End [COLOR=blue]Sub[/color]
[COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As Integer[/color]
[COLOR=green]'Unloads the image when the NX session terminates[/color]
GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination
End [COLOR=blue]Function[/color]
End [COLOR=blue]Module[/color]