#1 Thu 30 November 2006 13:36
- celine_ronte
- Participant occasionnel
- Lieu: Grenoble
- Date d'inscription: 5 Sep 2005
- Messages: 11
- Site web
Transfert des textes d'un dxf en shp
Bonjour,
Encore une question de ma part … !
J’ai un fichier dxf que je transfère en shp.
Les polylignes se transfèrent bien mais les textes deviennent soit un shape de type point, soit un shape de type annotations.
Existe t-il un moyen pour récupérer le texte et le placement de ce texte ? autre qu’une vectorisation de texte car je voudrait pouvoir modifier ce texte si jamais …
Merci encore à tous pour votre aide,
Céline
Hors ligne
#2 Thu 30 November 2006 16:09
- Philippe MUSSON
- Participant occasionnel
- Lieu: ANNECY
- Date d'inscription: 5 Sep 2005
- Messages: 42
Re: Transfert des textes d'un dxf en shp
Bonjour,
Moi aussi j'ai galéré un bon moment sur ce sujet.....
Depuis plusieurs années j'utilise (sur ArcView 3) un script trouvé sur
le site esri US qui convertit des étiquettes ArcView en DXF.
Dans un thème lignes, générer des étiquettes à partir du champ Text,
puis exécuter le script ci-dessous.
L'astuce majeure est de penser, dans la vue du projet, à mettre les
unités en pieds !!! script US oblige..
Bon courage
DEBUT DU SCRIPT ***********************
' View.ConvertLabelToDXF -> label2dxf.ave
' Bill Chappell 3/99 Modified script from Mark Scott(ESRI)
'
' Revised 8/99 To fix the graphic rotation with help from scripts
' from ESRI France(pcoolen@) and Scott Kutz ( esri.frskutz@) geoit.com
'
' Run from a Button, this script will create a DXF file from the
' text graphic in your current view. By then using the CAD reader
' extention you can view this as a theme. Remember under table
' properties to set visible the TEXT field. Once this is done, you
' can convert this to a shapefile, and autolabel on the TEXT field,
' Set line color to clear and start all over again......
' This dxf text file can then be viewed CAD or by using A/I it can
' be converted to an anno coverage
'
' Map Units should be set to FEET
'
Script.The.SetNumberFormat("d.dddddd")
theView = av.GetActiveDoc
viewScale = theView.ReturnScale
' Conversion factor: feet/point (text point size)
' 72 points per inch
' 1 point = 1/72 = 0.0138889 inches
' 1 point = 0.0138889/12 = 0.001157 feet
sizeUnitsPerPoint = 0.001157
' Define a scaling factor which is multiplied by the computed text
size
' to calculate the DXF text size. It may be necessary to adjust this
' value up or down to achieve a DXF text size acceptable for any
' given application.
scaleFact = 0.67
distPerPoint = sizeUnitsPerPoint * scaleFact
theDefault = "C:ARCVIEW.DXF".AsFileName
' Ask user for filename
myfile = FileDialog.Put(theDefault, "*.dxf", "Create DXF file")
if (myFile = nil) then
exit
end
' check if it has the dxf file extension, if not then add it.
lastFour = myFile.AsString.Right(4)
if (LastFour.Lcase ".dxf") then
newFile = myFile.AsString +".dxf"
myFile = newFile.AsFileName
end
theFile = LineFile.Make(myFile, #FILE_PERM_WRITE)
' Asking for Text Size NOT USED since I now calculate text size
'theTextSize = msgbox.Input( "Please Enter Text Size", "Text Size",
"10")
' if (theTextSize = nil) then
' exit
' end
' Let the user choose the extent of the graphics to be converted
' - All graphics in the View (theView.GetGraphics)
' - Graphics for a single Theme (theTheme.GetGraphics)
grafType = MsgBox.ChoiceAsString({"Entire View", "Theme"},
"Select scope of graphics to be converted:", "DXF Conversion Scope"
)
if (grafType = Nil) then
exit
end
if (grafType = "Theme") then
themeList = List.Make
for each d in theView.GetThemes
themeList.Add(d)
end
' Let the user choose the Theme to be processed.
theThemeName = MsgBox.ListAsString(themeList,"Select Theme Graphics
to convert", "Convert labels to DXF ")
if (theThemeName = nil) then
Exit
end
theTheme = theView.FindTheme(theThemeName.AsString)
theFTab = theTheme.GetFTab
theBitMap = theFTab.GetSelection
theGraphicsList = theTheme.GetGraphics ' Graphics list from the
theme
else
' Use the graphics list from the entire View
theGraphicsList = theView.GetGraphics ' Graphics list from the
view
end ' end of "if (grafType = "Single Theme") then"
counter = 0 ' Number of graphics processed
totalRecs = theGraphicsList.Count 'Number of Graphics to process
' Display information on the status line
av.ShowStopButton
av.ShowMsg("Converting"++myFile.AsString +"...")
' Force update to make messa
ge visible
System.RefreshWindows
theExtentRect = av.GetActiveDoc.ReturnExtent
theFile.WriteElt(" 0")
theFile.WriteElt("SECTION")
theFile.WriteElt(" 2")
theFile.WriteElt("HEADER")
theFile.WriteElt(" 9")
theFile.WriteElt("$ACADVER")
theFile.WriteElt(" 1")
theFile.WriteElt("AC1009")
theFile.WriteElt(" 9")
theFile.WriteElt("$INSBASE")
theFile.WriteElt(" 10")
theFile.WriteElt("0.0")
theFile.WriteElt(" 20")
theFile.WriteElt("0.0")
theFile.WriteElt(" 30")
theFile.WriteElt("0.0")
theFile.WriteElt(" 9")
theFile.WriteElt("$EXTMIN")
theFile.WriteElt(" 10")
theFile.WriteElt(theExtentRect.GetLeft.AsString)
theFile.WriteElt(" 20")
theFile.WriteElt(theExtentRect.GetBottom.AsString)
theFile.WriteElt(" 30")
theFile.WriteElt("0.0")
theFile.WriteElt(" 9")
theFile.WriteElt("$EXTMAX")
theFile.WriteElt(" 10")
theFile.WriteElt(theExtentRect.GetRight.AsString)
theFile.WriteElt(" 20")
theFile.WriteElt(theExtentRect.GetTop.AsString)
theFile.WriteElt(" 30")
theFile.WriteElt("0.0")
theFile.WriteElt(" 9")
theFile.WriteElt("$TEXTSTYLE")
theFile.WriteElt(" 7")
theFile.WriteElt("STANDARD")
theFile.WriteElt(" 0")
theFile.WriteElt("ENDSEC")
'TABLES SECTION
theFile.WriteElt(" 0")
theFile.WriteElt("SECTION")
theFile.WriteElt(" 2")
theFile.WriteElt("TABLES")
'LINETYPE TABLE
theFile.WriteElt(" 0")
theFile.WriteElt("TABLE")
theFile.WriteElt(" 2")
theFile.WriteElt("LTYPE")
theFile.WriteElt(" 70")
theFile.WriteElt(" 25")
theFile.WriteElt(" 0")
theFile.WriteElt("LTYPE")
theFile.WriteElt(" 2")
theFile.WriteElt("CONTINUOUS")
theFile.WriteElt(" 70")
theFile.WriteElt(" 0")
theFile.WriteElt(" 3")
theFile.WriteElt("Solid line")
theFile.WriteElt(" 72")
theFile.WriteElt(" 65")
theFile.WriteElt(" 73")
theFile.WriteElt(" 0")
theFile.WriteElt(" 40")
theFile.WriteElt("0.0")
theFile.WriteElt(" 0")
theFile.WriteElt("ENDTAB")
'LAYER TABLE
theFile.WriteElt(" 0")
theFile.WriteElt("TABLE")
theFile.WriteElt(" 2")
theFile.WriteElt("LAYER")
theFile.WriteElt(" 70")
theFile.WriteElt(" 2")
theFile.WriteElt(" 0")
theFile.WriteElt("LAYER")
theFile.WriteElt(" 2")
theFile.WriteElt("0")
theFile.WriteElt(" 70")
theFile.WriteElt(" 0")
theFile.WriteElt(" 62")
theFile.WriteElt(" 7")
theFile.WriteElt(" 6")
theFile.WriteElt("CONTINUOUS")
theFile.WriteElt(" 0")
theFile.WriteElt("LAYER")
theFile.WriteElt(" 2")
theFile.WriteElt("ARCVIEW_TEXT")
theFile.WriteElt(" 70")
theFile.WriteElt(" 0")
theFile.WriteElt(" 62")
theFile.WriteElt(" 1")
theFile.WriteElt(" 6")
theFile.WriteElt("CONTINUOUS")
theFile.WriteElt(" 0")
theFile.WriteElt("ENDTAB")
theFile.WriteElt(" 0")
theFile.WriteElt("ENDSEC")
theFile.WriteElt(" 0")
theFile.WriteElt("SECTION")
theFile.WriteElt(" 2")
theFile.WriteElt("ENTITIES")
for each theGraphic in av.GetActiveDoc.GetGraphics
if (theGraphic.Is(GraphicText)) then
counter = counter + 1
outputAngle = theGraphic.GetAngle Mod 360
rectOrigin = theGraphic.GetOrigin
textRect = theGraphic.GetBounds
width = textRect.GetWidth
height = textRect.GetHeight
' Text size for the DXF file, in feet (data base unit)
' (point size) * (feet/point) * (feet/feet)
textSizePt = theGraphic.GetSymbol.GetSize
' Comment out the following line if you uncommented the textsize
msgbox.
theTextSize = textSizePt * distPerPoint * viewScale
if (outputAngle = 0) then
textLowLeft = rectOrigin.Clone
else
dx = 0
dy = 0
gprime = theGraphic.clone
gprime.SetAngle(0)
rectOriginPrime = gprime.GetOrigin
textRectPrime = gprime.GetBounds
widthPrime = textRectPrime.GetWidth
cosAlpha = outputAngle.AsRadians.Cos
sinAlpha = outputAngle.AsRadians.Sin
if (sinAlpha > 0) then ' angle between 1 and
180 degrees
lAdjust = widthPrime * cosAlpha
dx = width - lAdjust
else ' angle
between 181 and
359 degrees
alphaPrime = outputAngle - 180
sinalphaPrime = alphaPrime.AsRadians.Sin
dy = widthPrime * sinalphaPrime
end ' end of "if (sinAlpha > 0) then"
textLowLeft = Point.Make( (rectOrigin.GetX +
dx),(rectOrigin.GetY + dy) )
end ' end of "if (outputAngle = 0) then"
outputXcoord = textLowLeft.GetX
outputYcoord = textLowLeft.GetY
theFile.WriteElt(" 0")
theFile.WriteElt("TEXT")
theFile.WriteElt(" 8")
theFile.WriteElt("ARCVIEW_TEXT")
theFile.WriteElt(" 10")
theFile.WriteElt(outputXcoord.AsString )
theFile.WriteElt(" 20")
theFile.WriteElt(outputYcoord.AsString)
theFile.WriteElt(" 30")
theFile.WriteElt("0.0")
theFile.WriteElt(" 40")
theFile.WriteElt(theTextSize.AsString)
theFile.WriteElt(" 1")
theFile.WriteElt(theGraphic.GetText)
theFile.WriteElt( " 50 ") ' Text Angle, degrees
theFile.WriteElt( outputAngle.AsString )
' Reflect progress on the status line
progress = (counter / totalRecs) * 100
proceed = av.SetStatus( progress )
if (proceed.Not) then
av.ClearStatus
av.ShowMsg( "Stopped" )
end
end
end
theFile.WriteElt(" 0")
theFile.WriteElt("ENDSEC")
theFile.WriteElt(" 0")
theFile.WriteElt("EOF")
'
==========================================================================
'| Cleanup and Summary Processing
|
'
==========================================================================
' Clear the status line
av.ClearStatus
av.ClearMsg
theFile.Flush
theFile.Close
msgbox.info(theFile.AsString +" Is Finished","")
msgbox.info("After adding the DXF annotation theme"+NL+"Remember under
Table Properties,"+NL+"to Set the Text field Visible","")
FIN DU SCRIPT ******************
Cordialement
Philippe MUSSON
Responsable technique SIG
Département de l'Aménagement Urbain
Direction de l'Urbanisme et du Plan
Hôtel de Ville
BP 2305
74011 ANNECY CEDEX
Tél: 04.50.33.89.58
Fax: 04.50.33.89.03
Mail: philippe.musson@ ville-annecy.fr
Hors ligne