private const rationone=0
private const ratiowidth=1
private const ratioheight=2
dim odocument
dim osheets
dim osheet
dim oview
dim opictures
public sub catmain()
on error resume next
set odocument = catia.activedocument
if err.number <> 0 then
set odocument = catia.documents.add("drawing")
err.clear
end if
on error goto 0
set osheets = odocument.sheets
set osheet = osheets.activesheet
set oview = osheet.views.activeview
set opictures = oview.pictures
msgbox "the macro will insert a jpg file in your drawing at position x =150, y =0. the file must be in the folder c:\temp\ (which should be created before runnning the macro) and must have the name logo. modify the code if you want something else"
insertpicture "c:\temp\coe_logo.jpg", 150, 0, ratioheight, 100,25
end sub
sub insertpicture (strpath , dblanchorx, dblanchory, prratio, dblwidth, dblheight)
dim objpicture
set objpicture = opictures.add(strpath, dblanchorx, dblanchory)
formatpicture objpicture, prratio,-1 ,-1 , dblwidth, dblheight
set objpicture = nothing
end sub
public sub formatpicture(objpicture , prratio , dblanchorx, dblanchory, dblwidth , dblheight )
dim dblscalar
if dblanchorx >= 0 then objpicture.x = dblanchorx
if dblanchory >= 0 then objpicture.y = dblanchory
if prratio = ratiowidth then
'picture scaled by width with fixed ratio
if dblwidth > 0 then
dblscalar = objpicture.width / dblwidth
objpicture.height = objpicture.height / dblscalar
objpicture.width = dblwidth
end if
elseif prratio = ratioheight then
'picture scaled by height with fixed ratio
if dblheight > 0 then
dblscalar = objpicture.height / dblheight
objpicture.width = objpicture.width / dblscalar
objpicture.height = dblheight
end if
else
'picture scaled by width & height
if dblwidth > 0 then objpicture.width = dblwidth
if dblheight > 0 then objpicture.height = dblheight
end if
end sub
ps es un catscript